
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>turtle --- 海龟绘图 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="cmd --- 支持面向行的命令解释器" href="cmd.html" />
    <link rel="prev" title="程序框架" href="frameworks.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/turtle.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="cmd.html" title="cmd --- 支持面向行的命令解释器"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="frameworks.html" title="程序框架"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="frameworks.html" accesskey="U">程序框架</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-turtle">
<span id="turtle-turtle-graphics"></span><h1><a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> --- 海龟绘图<a class="headerlink" href="#module-turtle" title="永久链接至标题">¶</a></h1>
<p><strong>源码：</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/turtle.py">Lib/turtle.py</a></p>
<hr class="docutils" />
<div class="section" id="introduction">
<h2>概述<a class="headerlink" href="#introduction" title="永久链接至标题">¶</a></h2>
<p>海龟绘图很适合用来引导孩子学习编程。 最初来自于 Wally Feurzeig, Seymour Papert 和 Cynthia Solomon 于 1967 年所创造的 Logo 编程语言。</p>
<p>请想象绘图区有一只机器海龟，起始位置在 x-y 平面的 (0, 0) 点。先执行 <code class="docutils literal notranslate"><span class="pre">import</span> <span class="pre">turtle</span></code>，再执行 <code class="docutils literal notranslate"><span class="pre">turtle.forward(15)</span></code>，它将(在屏幕上)朝所面对的 x 轴正方向前进 15 像素，随着它的移动画出一条线段。再执行 <code class="docutils literal notranslate"><span class="pre">turtle.right(25)</span></code>，它将原地右转 25 度。</p>
<div class="sidebar">
<p class="sidebar-title">Turtle star</p>
<p>使用海龟绘图可以编写重复执行简单动作的程序画出精细复杂的形状。</p>
<img alt="../_images/turtle-star.png" class="align-center" src="../_images/turtle-star.png" />
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">turtle</span> <span class="kn">import</span> <span class="o">*</span>
<span class="n">color</span><span class="p">(</span><span class="s1">&#39;red&#39;</span><span class="p">,</span> <span class="s1">&#39;yellow&#39;</span><span class="p">)</span>
<span class="n">begin_fill</span><span class="p">()</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
    <span class="n">forward</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span>
    <span class="n">left</span><span class="p">(</span><span class="mi">170</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">abs</span><span class="p">(</span><span class="n">pos</span><span class="p">())</span> <span class="o">&lt;</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">break</span>
<span class="n">end_fill</span><span class="p">()</span>
<span class="n">done</span><span class="p">()</span>
</pre></div>
</div>
</div>
<p>通过组合使用此类命令，可以轻松地绘制出精美的形状和图案。</p>
<p><a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 模块是基于 Python 标准发行版 2.5 以来的同名模块重新编写并进行了功能扩展。</p>
<p>新模块尽量保持了原模块的特点，并且(几乎)100%与其兼容。这就意味着初学编程者能够以交互方式使用模块的所有命令、类和方法——运行 IDLE 时注意加 <code class="docutils literal notranslate"><span class="pre">-n</span></code> 参数。</p>
<p>turtle 模块提供面向对象和面向过程两种形式的海龟绘图基本组件。由于它使用 <a class="reference internal" href="tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a> 实现基本图形界面，因此需要安装了 Tk 支持的 Python 版本。</p>
<p>面向对象的接口主要使用“2+2”个类：</p>
<ol class="arabic">
<li><p><a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> 类定义图形窗口作为绘图海龟的运动场。它的构造器需要一个 <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> 或 <a class="reference internal" href="#turtle.ScrolledCanvas" title="turtle.ScrolledCanvas"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScrolledCanvas</span></code></a> 作为参数。应在 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 作为某个程序的一部分的时候使用。</p>
<p><a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-func docutils literal notranslate"><span class="pre">Screen()</span></code></a> 函数返回一个 <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> 子类的单例对象。此函数应在 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 作为独立绘图工具时使用。作为一个单例对象，其所属的类是不可被继承的。</p>
<p>TurtleScreen/Screen 的所有方法还存在对应的函数，即作为面向过程的接口组成部分。</p>
</li>
<li><p><a class="reference internal" href="#turtle.RawTurtle" title="turtle.RawTurtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawTurtle</span></code></a> (别名: <a class="reference internal" href="#turtle.RawPen" title="turtle.RawPen"><code class="xref py py-class docutils literal notranslate"><span class="pre">RawPen</span></code></a>) 类定义海龟对象在 <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> 上绘图。它的构造器需要一个 Canvas, ScrolledCanvas 或 TurtleScreen 作为参数，以指定 RawTurtle 对象在哪里绘图。</p>
<p>从 RawTurtle 派生出子类 <a class="reference internal" href="#turtle.Turtle" title="turtle.Turtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">Turtle</span></code></a> (别名: <code class="xref py py-class docutils literal notranslate"><span class="pre">Pen</span></code>)，该类对象在 <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> 实例上绘图，如果实例不存在则会自动创建。</p>
<p>RawTurtle/Turtle 的所有方法也存在对应的函数，即作为面向过程的接口组成部分。</p>
</li>
</ol>
<p>过程式接口提供与 <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> 和 <a class="reference internal" href="#turtle.Turtle" title="turtle.Turtle"><code class="xref py py-class docutils literal notranslate"><span class="pre">Turtle</span></code></a> 类的方法相对应的函数。函数名与对应的方法名相同。当 Screen 类的方法对应函数被调用时会自动创建一个 Screen 对象。当 Turtle 类的方法对应函数被调用时会自动创建一个 (匿名的) Turtle 对象。</p>
<p>如果屏幕上需要有多个海龟，就必须使用面向对象的接口。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>以下文档给出了函数的参数列表。对于方法来说当然还有额外的第一个参数 <em>self</em>，这里省略了。</p>
</div>
</div>
<div class="section" id="overview-of-available-turtle-and-screen-methods">
<h2>可用的 Turtle 和 Screen 方法概览<a class="headerlink" href="#overview-of-available-turtle-and-screen-methods" title="永久链接至标题">¶</a></h2>
<div class="section" id="turtle-methods">
<h3>Turtle 方法<a class="headerlink" href="#turtle-methods" title="永久链接至标题">¶</a></h3>
<dl>
<dt>海龟动作</dt><dd><dl>
<dt>移动和绘制</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.forward" title="turtle.forward"><code class="xref py py-func docutils literal notranslate"><span class="pre">forward()</span></code></a> | <a class="reference internal" href="#turtle.fd" title="turtle.fd"><code class="xref py py-func docutils literal notranslate"><span class="pre">fd()</span></code></a> 前进</div>
<div class="line"><a class="reference internal" href="#turtle.backward" title="turtle.backward"><code class="xref py py-func docutils literal notranslate"><span class="pre">backward()</span></code></a> | <a class="reference internal" href="#turtle.bk" title="turtle.bk"><code class="xref py py-func docutils literal notranslate"><span class="pre">bk()</span></code></a> | <a class="reference internal" href="#turtle.back" title="turtle.back"><code class="xref py py-func docutils literal notranslate"><span class="pre">back()</span></code></a> 后退</div>
<div class="line"><a class="reference internal" href="#turtle.right" title="turtle.right"><code class="xref py py-func docutils literal notranslate"><span class="pre">right()</span></code></a> | <a class="reference internal" href="#turtle.rt" title="turtle.rt"><code class="xref py py-func docutils literal notranslate"><span class="pre">rt()</span></code></a> 右转</div>
<div class="line"><a class="reference internal" href="#turtle.left" title="turtle.left"><code class="xref py py-func docutils literal notranslate"><span class="pre">left()</span></code></a> | <a class="reference internal" href="#turtle.lt" title="turtle.lt"><code class="xref py py-func docutils literal notranslate"><span class="pre">lt()</span></code></a> 左转</div>
<div class="line"><a class="reference internal" href="#turtle.goto" title="turtle.goto"><code class="xref py py-func docutils literal notranslate"><span class="pre">goto()</span></code></a> | <a class="reference internal" href="#turtle.setpos" title="turtle.setpos"><code class="xref py py-func docutils literal notranslate"><span class="pre">setpos()</span></code></a> | <a class="reference internal" href="#turtle.setposition" title="turtle.setposition"><code class="xref py py-func docutils literal notranslate"><span class="pre">setposition()</span></code></a> 前往/定位</div>
<div class="line"><a class="reference internal" href="#turtle.setx" title="turtle.setx"><code class="xref py py-func docutils literal notranslate"><span class="pre">setx()</span></code></a> 设置x坐标</div>
<div class="line"><a class="reference internal" href="#turtle.sety" title="turtle.sety"><code class="xref py py-func docutils literal notranslate"><span class="pre">sety()</span></code></a> 设置y坐标</div>
<div class="line"><a class="reference internal" href="#turtle.setheading" title="turtle.setheading"><code class="xref py py-func docutils literal notranslate"><span class="pre">setheading()</span></code></a> | <a class="reference internal" href="#turtle.seth" title="turtle.seth"><code class="xref py py-func docutils literal notranslate"><span class="pre">seth()</span></code></a> 设置朝向</div>
<div class="line"><a class="reference internal" href="#turtle.home" title="turtle.home"><code class="xref py py-func docutils literal notranslate"><span class="pre">home()</span></code></a> 返回原点</div>
<div class="line"><a class="reference internal" href="#turtle.circle" title="turtle.circle"><code class="xref py py-func docutils literal notranslate"><span class="pre">circle()</span></code></a> 画圆</div>
<div class="line"><a class="reference internal" href="#turtle.dot" title="turtle.dot"><code class="xref py py-func docutils literal notranslate"><span class="pre">dot()</span></code></a> 画点</div>
<div class="line"><a class="reference internal" href="#turtle.stamp" title="turtle.stamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code></a> 印章</div>
<div class="line"><a class="reference internal" href="#turtle.clearstamp" title="turtle.clearstamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearstamp()</span></code></a> 清除印章</div>
<div class="line"><a class="reference internal" href="#turtle.clearstamps" title="turtle.clearstamps"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearstamps()</span></code></a> 清除多个印章</div>
<div class="line"><a class="reference internal" href="#turtle.undo" title="turtle.undo"><code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></a> 撤消</div>
<div class="line"><a class="reference internal" href="#turtle.speed" title="turtle.speed"><code class="xref py py-func docutils literal notranslate"><span class="pre">speed()</span></code></a> 速度</div>
</div>
</dd>
<dt>获取海龟的状态</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.position" title="turtle.position"><code class="xref py py-func docutils literal notranslate"><span class="pre">position()</span></code></a> | <a class="reference internal" href="#turtle.pos" title="turtle.pos"><code class="xref py py-func docutils literal notranslate"><span class="pre">pos()</span></code></a> 位置</div>
<div class="line"><a class="reference internal" href="#turtle.towards" title="turtle.towards"><code class="xref py py-func docutils literal notranslate"><span class="pre">towards()</span></code></a> 目标方向</div>
<div class="line"><a class="reference internal" href="#turtle.xcor" title="turtle.xcor"><code class="xref py py-func docutils literal notranslate"><span class="pre">xcor()</span></code></a> x坐标</div>
<div class="line"><a class="reference internal" href="#turtle.ycor" title="turtle.ycor"><code class="xref py py-func docutils literal notranslate"><span class="pre">ycor()</span></code></a> y坐标</div>
<div class="line"><a class="reference internal" href="#turtle.heading" title="turtle.heading"><code class="xref py py-func docutils literal notranslate"><span class="pre">heading()</span></code></a> 朝向</div>
<div class="line"><a class="reference internal" href="#turtle.distance" title="turtle.distance"><code class="xref py py-func docutils literal notranslate"><span class="pre">distance()</span></code></a> 距离</div>
</div>
</dd>
<dt>设置与度量单位</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a> 角度</div>
<div class="line"><a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a> 弧度</div>
</div>
</dd>
</dl>
</dd>
<dt>画笔控制</dt><dd><dl>
<dt>绘图状态</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.pendown" title="turtle.pendown"><code class="xref py py-func docutils literal notranslate"><span class="pre">pendown()</span></code></a> | <a class="reference internal" href="#turtle.pd" title="turtle.pd"><code class="xref py py-func docutils literal notranslate"><span class="pre">pd()</span></code></a> | <a class="reference internal" href="#turtle.down" title="turtle.down"><code class="xref py py-func docutils literal notranslate"><span class="pre">down()</span></code></a> 画笔落下</div>
<div class="line"><a class="reference internal" href="#turtle.penup" title="turtle.penup"><code class="xref py py-func docutils literal notranslate"><span class="pre">penup()</span></code></a> | <a class="reference internal" href="#turtle.pu" title="turtle.pu"><code class="xref py py-func docutils literal notranslate"><span class="pre">pu()</span></code></a> | <a class="reference internal" href="#turtle.up" title="turtle.up"><code class="xref py py-func docutils literal notranslate"><span class="pre">up()</span></code></a> 画笔抬起</div>
<div class="line"><a class="reference internal" href="#turtle.pensize" title="turtle.pensize"><code class="xref py py-func docutils literal notranslate"><span class="pre">pensize()</span></code></a> | <a class="reference internal" href="#turtle.width" title="turtle.width"><code class="xref py py-func docutils literal notranslate"><span class="pre">width()</span></code></a> 画笔粗细</div>
<div class="line"><a class="reference internal" href="#turtle.pen" title="turtle.pen"><code class="xref py py-func docutils literal notranslate"><span class="pre">pen()</span></code></a> 画笔</div>
<div class="line"><a class="reference internal" href="#turtle.isdown" title="turtle.isdown"><code class="xref py py-func docutils literal notranslate"><span class="pre">isdown()</span></code></a> 画笔是否落下</div>
</div>
</dd>
<dt>颜色控制</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.color" title="turtle.color"><code class="xref py py-func docutils literal notranslate"><span class="pre">color()</span></code></a> 颜色</div>
<div class="line"><a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a> 画笔颜色</div>
<div class="line"><a class="reference internal" href="#turtle.fillcolor" title="turtle.fillcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">fillcolor()</span></code></a> 填充颜色</div>
</div>
</dd>
<dt>填充</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.filling" title="turtle.filling"><code class="xref py py-func docutils literal notranslate"><span class="pre">filling()</span></code></a> 是否填充</div>
<div class="line"><a class="reference internal" href="#turtle.begin_fill" title="turtle.begin_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_fill()</span></code></a> 开始填充</div>
<div class="line"><a class="reference internal" href="#turtle.end_fill" title="turtle.end_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">end_fill()</span></code></a> 结束填充</div>
</div>
</dd>
<dt>更多绘图控制</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.reset" title="turtle.reset"><code class="xref py py-func docutils literal notranslate"><span class="pre">reset()</span></code></a> 重置</div>
<div class="line"><a class="reference internal" href="#turtle.clear" title="turtle.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a> 清空</div>
<div class="line"><a class="reference internal" href="#turtle.write" title="turtle.write"><code class="xref py py-func docutils literal notranslate"><span class="pre">write()</span></code></a> 书写</div>
</div>
</dd>
</dl>
</dd>
<dt>海龟状态</dt><dd><dl>
<dt>可见性</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.showturtle" title="turtle.showturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">showturtle()</span></code></a> | <a class="reference internal" href="#turtle.st" title="turtle.st"><code class="xref py py-func docutils literal notranslate"><span class="pre">st()</span></code></a> 显示海龟</div>
<div class="line"><a class="reference internal" href="#turtle.hideturtle" title="turtle.hideturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">hideturtle()</span></code></a> | <a class="reference internal" href="#turtle.ht" title="turtle.ht"><code class="xref py py-func docutils literal notranslate"><span class="pre">ht()</span></code></a> 隐藏海龟</div>
<div class="line"><a class="reference internal" href="#turtle.isvisible" title="turtle.isvisible"><code class="xref py py-func docutils literal notranslate"><span class="pre">isvisible()</span></code></a> 是否可见</div>
</div>
</dd>
<dt>外观</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.shape" title="turtle.shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">shape()</span></code></a> 形状</div>
<div class="line"><a class="reference internal" href="#turtle.resizemode" title="turtle.resizemode"><code class="xref py py-func docutils literal notranslate"><span class="pre">resizemode()</span></code></a> 大小调整模式</div>
<div class="line"><a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a> | <a class="reference internal" href="#turtle.turtlesize" title="turtle.turtlesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtlesize()</span></code></a> 形状大小</div>
<div class="line"><a class="reference internal" href="#turtle.shearfactor" title="turtle.shearfactor"><code class="xref py py-func docutils literal notranslate"><span class="pre">shearfactor()</span></code></a> 剪切因子</div>
<div class="line"><a class="reference internal" href="#turtle.settiltangle" title="turtle.settiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">settiltangle()</span></code></a> 设置倾角</div>
<div class="line"><a class="reference internal" href="#turtle.tiltangle" title="turtle.tiltangle"><code class="xref py py-func docutils literal notranslate"><span class="pre">tiltangle()</span></code></a> 倾角</div>
<div class="line"><a class="reference internal" href="#turtle.tilt" title="turtle.tilt"><code class="xref py py-func docutils literal notranslate"><span class="pre">tilt()</span></code></a> 倾斜</div>
<div class="line"><a class="reference internal" href="#turtle.shapetransform" title="turtle.shapetransform"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapetransform()</span></code></a> 变形</div>
<div class="line"><a class="reference internal" href="#turtle.get_shapepoly" title="turtle.get_shapepoly"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_shapepoly()</span></code></a> 获取形状多边形</div>
</div>
</dd>
</dl>
</dd>
<dt>使用事件</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.onclick" title="turtle.onclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code></a> 当鼠标点击</div>
<div class="line"><a class="reference internal" href="#turtle.onrelease" title="turtle.onrelease"><code class="xref py py-func docutils literal notranslate"><span class="pre">onrelease()</span></code></a> 当鼠标释放</div>
<div class="line"><a class="reference internal" href="#turtle.ondrag" title="turtle.ondrag"><code class="xref py py-func docutils literal notranslate"><span class="pre">ondrag()</span></code></a> 当鼠标拖动</div>
</div>
</dd>
<dt>特殊海龟方法</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.begin_poly" title="turtle.begin_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_poly()</span></code></a> 开始记录多边形</div>
<div class="line"><a class="reference internal" href="#turtle.end_poly" title="turtle.end_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">end_poly()</span></code></a> 结束记录多边形</div>
<div class="line"><a class="reference internal" href="#turtle.get_poly" title="turtle.get_poly"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_poly()</span></code></a> 获取多边形</div>
<div class="line"><a class="reference internal" href="#turtle.clone" title="turtle.clone"><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code></a> 克隆</div>
<div class="line"><a class="reference internal" href="#turtle.getturtle" title="turtle.getturtle"><code class="xref py py-func docutils literal notranslate"><span class="pre">getturtle()</span></code></a> | <a class="reference internal" href="#turtle.getpen" title="turtle.getpen"><code class="xref py py-func docutils literal notranslate"><span class="pre">getpen()</span></code></a> 获取海龟画笔</div>
<div class="line"><a class="reference internal" href="#turtle.getscreen" title="turtle.getscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">getscreen()</span></code></a> 获取屏幕</div>
<div class="line"><a class="reference internal" href="#turtle.setundobuffer" title="turtle.setundobuffer"><code class="xref py py-func docutils literal notranslate"><span class="pre">setundobuffer()</span></code></a> 设置撤消缓冲区</div>
<div class="line"><a class="reference internal" href="#turtle.undobufferentries" title="turtle.undobufferentries"><code class="xref py py-func docutils literal notranslate"><span class="pre">undobufferentries()</span></code></a> 撤消缓冲区条目数</div>
</div>
</dd>
</dl>
</div>
<div class="section" id="methods-of-turtlescreen-screen">
<h3>TurtleScreen/Screen 方法<a class="headerlink" href="#methods-of-turtlescreen-screen" title="永久链接至标题">¶</a></h3>
<dl>
<dt>窗口控制</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.bgcolor" title="turtle.bgcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">bgcolor()</span></code></a> 背景颜色</div>
<div class="line"><a class="reference internal" href="#turtle.bgpic" title="turtle.bgpic"><code class="xref py py-func docutils literal notranslate"><span class="pre">bgpic()</span></code></a> 背景图片</div>
<div class="line"><a class="reference internal" href="#turtle.clear" title="turtle.clear"><code class="xref py py-func docutils literal notranslate"><span class="pre">clear()</span></code></a> | <a class="reference internal" href="#turtle.clearscreen" title="turtle.clearscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">clearscreen()</span></code></a> 清屏</div>
<div class="line"><a class="reference internal" href="#turtle.reset" title="turtle.reset"><code class="xref py py-func docutils literal notranslate"><span class="pre">reset()</span></code></a> | <a class="reference internal" href="#turtle.resetscreen" title="turtle.resetscreen"><code class="xref py py-func docutils literal notranslate"><span class="pre">resetscreen()</span></code></a> 重置</div>
<div class="line"><a class="reference internal" href="#turtle.screensize" title="turtle.screensize"><code class="xref py py-func docutils literal notranslate"><span class="pre">screensize()</span></code></a> 屏幕大小</div>
<div class="line"><a class="reference internal" href="#turtle.setworldcoordinates" title="turtle.setworldcoordinates"><code class="xref py py-func docutils literal notranslate"><span class="pre">setworldcoordinates()</span></code></a> 设置世界坐标系</div>
</div>
</dd>
<dt>动画控制</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.delay" title="turtle.delay"><code class="xref py py-func docutils literal notranslate"><span class="pre">delay()</span></code></a> 延迟</div>
<div class="line"><a class="reference internal" href="#turtle.tracer" title="turtle.tracer"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracer()</span></code></a> 追踪</div>
<div class="line"><a class="reference internal" href="#turtle.update" title="turtle.update"><code class="xref py py-func docutils literal notranslate"><span class="pre">update()</span></code></a> 更新</div>
</div>
</dd>
<dt>使用屏幕事件</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a> 监听</div>
<div class="line"><a class="reference internal" href="#turtle.onkey" title="turtle.onkey"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkey()</span></code></a> | <a class="reference internal" href="#turtle.onkeyrelease" title="turtle.onkeyrelease"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkeyrelease()</span></code></a> 当键盘按下并释放</div>
<div class="line"><a class="reference internal" href="#turtle.onkeypress" title="turtle.onkeypress"><code class="xref py py-func docutils literal notranslate"><span class="pre">onkeypress()</span></code></a> 当键盘按下</div>
<div class="line"><a class="reference internal" href="#turtle.onclick" title="turtle.onclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code></a> | <a class="reference internal" href="#turtle.onscreenclick" title="turtle.onscreenclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">onscreenclick()</span></code></a> 当点击屏幕</div>
<div class="line"><a class="reference internal" href="#turtle.ontimer" title="turtle.ontimer"><code class="xref py py-func docutils literal notranslate"><span class="pre">ontimer()</span></code></a> 当达到定时</div>
<div class="line"><a class="reference internal" href="#turtle.mainloop" title="turtle.mainloop"><code class="xref py py-func docutils literal notranslate"><span class="pre">mainloop()</span></code></a> | <a class="reference internal" href="#turtle.done" title="turtle.done"><code class="xref py py-func docutils literal notranslate"><span class="pre">done()</span></code></a> 主循环</div>
</div>
</dd>
<dt>设置与特殊方法</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a></div>
<div class="line"><a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a> 颜色模式</div>
<div class="line"><a class="reference internal" href="#turtle.getcanvas" title="turtle.getcanvas"><code class="xref py py-func docutils literal notranslate"><span class="pre">getcanvas()</span></code></a> 获取画布</div>
<div class="line"><a class="reference internal" href="#turtle.getshapes" title="turtle.getshapes"><code class="xref py py-func docutils literal notranslate"><span class="pre">getshapes()</span></code></a> 获取形状</div>
<div class="line"><a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a> | <a class="reference internal" href="#turtle.addshape" title="turtle.addshape"><code class="xref py py-func docutils literal notranslate"><span class="pre">addshape()</span></code></a> 添加形状</div>
<div class="line"><a class="reference internal" href="#turtle.turtles" title="turtle.turtles"><code class="xref py py-func docutils literal notranslate"><span class="pre">turtles()</span></code></a> 所有海龟</div>
<div class="line"><a class="reference internal" href="#turtle.window_height" title="turtle.window_height"><code class="xref py py-func docutils literal notranslate"><span class="pre">window_height()</span></code></a> 窗口高度</div>
<div class="line"><a class="reference internal" href="#turtle.window_width" title="turtle.window_width"><code class="xref py py-func docutils literal notranslate"><span class="pre">window_width()</span></code></a> 窗口宽度</div>
</div>
</dd>
<dt>输入方法</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.textinput" title="turtle.textinput"><code class="xref py py-func docutils literal notranslate"><span class="pre">textinput()</span></code></a> 文本输入</div>
<div class="line"><a class="reference internal" href="#turtle.numinput" title="turtle.numinput"><code class="xref py py-func docutils literal notranslate"><span class="pre">numinput()</span></code></a> 数字输入</div>
</div>
</dd>
<dt>Screen 专有方法</dt><dd><div class="line-block">
<div class="line"><a class="reference internal" href="#turtle.bye" title="turtle.bye"><code class="xref py py-func docutils literal notranslate"><span class="pre">bye()</span></code></a> 退出</div>
<div class="line"><a class="reference internal" href="#turtle.exitonclick" title="turtle.exitonclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">exitonclick()</span></code></a> 当点击时退出</div>
<div class="line"><a class="reference internal" href="#turtle.setup" title="turtle.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></a> 设置</div>
<div class="line"><a class="reference internal" href="#turtle.title" title="turtle.title"><code class="xref py py-func docutils literal notranslate"><span class="pre">title()</span></code></a> 标题</div>
</div>
</dd>
</dl>
</div>
</div>
<div class="section" id="methods-of-rawturtle-turtle-and-corresponding-functions">
<h2>RawTurtle/Turtle 方法和对应函数<a class="headerlink" href="#methods-of-rawturtle-turtle-and-corresponding-functions" title="永久链接至标题">¶</a></h2>
<p>本节中的大部分示例都使用 Turtle 类的一个实例，命名为 <code class="docutils literal notranslate"><span class="pre">turtle</span></code>。</p>
<div class="section" id="turtle-motion">
<h3>海龟动作<a class="headerlink" href="#turtle-motion" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.forward">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.forward" title="永久链接至目标">¶</a></dt>
<dt id="turtle.fd">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">fd</code><span class="sig-paren">(</span><em class="sig-param">distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.fd" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>distance</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>海龟前进 <em>distance</em> 指定的距离，方向为海龟的朝向。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(25.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="o">-</span><span class="mi">75</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(-50.00,0.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.back">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">back</code><span class="sig-paren">(</span><em class="sig-param">distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.back" title="永久链接至目标">¶</a></dt>
<dt id="turtle.bk">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">bk</code><span class="sig-paren">(</span><em class="sig-param">distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bk" title="永久链接至目标">¶</a></dt>
<dt id="turtle.backward">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">backward</code><span class="sig-paren">(</span><em class="sig-param">distance</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.backward" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>distance</strong> -- 一个数值</p>
</dd>
</dl>
<p>海龟后退 <em>distance</em> 指定的距离，方向与海龟的朝向相反。不改变海龟的朝向。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">backward</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(-30.00,0.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.right">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">right</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.right" title="永久链接至目标">¶</a></dt>
<dt id="turtle.rt">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">rt</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.rt" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>angle</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>海龟右转 <em>angle</em> 个单位。(单位默认为角度，但可通过 <a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a> 和 <a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a> 函数改变设置。) 角度的正负由海龟模式确定，参见 <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">22.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">right</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">337.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.left">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">left</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.left" title="永久链接至目标">¶</a></dt>
<dt id="turtle.lt">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">lt</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.lt" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>angle</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>海龟左转 <em>angle</em> 个单位。(单位默认为角度，但可通过 <a class="reference internal" href="#turtle.degrees" title="turtle.degrees"><code class="xref py py-func docutils literal notranslate"><span class="pre">degrees()</span></code></a> 和 <a class="reference internal" href="#turtle.radians" title="turtle.radians"><code class="xref py py-func docutils literal notranslate"><span class="pre">radians()</span></code></a> 函数改变设置。) 角度的正负由海龟模式确定，参见 <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">22.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">67.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.goto">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">goto</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.goto" title="永久链接至目标">¶</a></dt>
<dt id="turtle.setpos">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setpos</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setpos" title="永久链接至目标">¶</a></dt>
<dt id="turtle.setposition">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setposition</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setposition" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> -- 一个数值或数值对/向量</p></li>
<li><p><strong>y</strong> -- 一个数值或 <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
</ul>
</dd>
</dl>
<p>如果 <em>y</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，<em>x</em> 应为一个表示坐标的数值对或 <a class="reference internal" href="#turtle.Vec2D" title="turtle.Vec2D"><code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code></a> 类对象 (例如 <a class="reference internal" href="#turtle.pos" title="turtle.pos"><code class="xref py py-func docutils literal notranslate"><span class="pre">pos()</span></code></a> 返回的对象).</p>
<p>海龟移动到一个绝对坐标。如果画笔已落下将会画线。不改变海龟的朝向。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">tp</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tp</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">(</span><span class="mi">60</span><span class="p">,</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="go">(60.00,30.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">((</span><span class="mi">20</span><span class="p">,</span><span class="mi">80</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="go">(20.00,80.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setpos</span><span class="p">(</span><span class="n">tp</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.setx">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setx</code><span class="sig-paren">(</span><em class="sig-param">x</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setx" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>x</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>设置海龟的横坐标为 <em>x</em>，纵坐标保持不变。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,240.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setx</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(10.00,240.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.sety">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">sety</code><span class="sig-paren">(</span><em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.sety" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>y</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>设置海龟的纵坐标为 <em>y</em>，横坐标保持不变。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,40.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">sety</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,-10.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.setheading">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setheading</code><span class="sig-paren">(</span><em class="sig-param">to_angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setheading" title="永久链接至目标">¶</a></dt>
<dt id="turtle.seth">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">seth</code><span class="sig-paren">(</span><em class="sig-param">to_angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.seth" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>to_angle</strong> -- 一个数值 (整型或浮点型)</p>
</dd>
</dl>
<p>设置海龟的朝向为 <em>to_angle</em>。以下是以角度表示的几个常用方向：</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 49%" />
<col style="width: 51%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>标准模式</p></th>
<th class="head"><p>logo 模式</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>0 - 东</p></td>
<td><p>0 - 北</p></td>
</tr>
<tr class="row-odd"><td><p>90 - 北</p></td>
<td><p>90 - 东</p></td>
</tr>
<tr class="row-even"><td><p>180 - 西</p></td>
<td><p>180 - 南</p></td>
</tr>
<tr class="row-odd"><td><p>270 - 南</p></td>
<td><p>270 - 西</p></td>
</tr>
</tbody>
</table>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setheading</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">90.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.home">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">home</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.home" title="永久链接至目标">¶</a></dt>
<dd><p>海龟移至初始坐标 (0,0)，并设置朝向为初始方向 (由海龟模式确定，参见 <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">90.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,-10.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">0.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.circle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">circle</code><span class="sig-paren">(</span><em class="sig-param">radius</em>, <em class="sig-param">extent=None</em>, <em class="sig-param">steps=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.circle" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>radius</strong> -- 一个数值</p></li>
<li><p><strong>extent</strong> -- 一个数值 (或 <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p></li>
<li><p><strong>steps</strong> -- 一个整型数 (或 <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p></li>
</ul>
</dd>
</dl>
<p>绘制一个 <em>radius</em> 指定半径的圆。圆心在海龟左边 <em>radius</em> 个单位；<em>extent</em> 为一个夹角，用来决定绘制圆的一部分。如未指定 <em>extent*则绘制整个圆。如果 *extent</em> 不是完整圆周，则以当前画笔位置为一个端点绘制圆弧。如果 <em>radius</em> 为正值则朝逆时针方向绘制圆弧，否则朝顺时针方向。最终海龟的朝向会依据 <em>extent</em> 的值而改变。</p>
<p>圆实际是以其内切正多边形来近似表示的，其边的数量由 <em>steps</em> 指定。如果未指定边数则会自动确定。此方法也可用来绘制正多边形。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">0.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(-0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">0.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">120</span><span class="p">,</span> <span class="mi">180</span><span class="p">)</span>  <span class="c1"># draw a semicircle</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,240.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">180.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.dot">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">dot</code><span class="sig-paren">(</span><em class="sig-param">size=None</em>, <em class="sig-param">*color</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.dot" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>size</strong> -- 一个整型数 &gt;= 1 (如果指定)</p></li>
<li><p><strong>color</strong> -- 一个颜色字符串或颜色数值元组</p></li>
</ul>
</dd>
</dl>
<p>绘制一个直径为 <em>size</em>，颜色为 <em>color</em> 的圆点。如果 <em>size</em> 未指定，则直径取 pensize+4 和 2*pensize 中的较大值。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">dot</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="s2">&quot;blue&quot;</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(100.00,-0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">0.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.stamp">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">stamp</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.stamp" title="永久链接至目标">¶</a></dt>
<dd><p>在海龟当前位置印制一个海龟形状。返回该印章的 stamp_id，印章可以通过调用 <code class="docutils literal notranslate"><span class="pre">clearstamp(stamp_id)</span></code> 来删除。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;blue&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">()</span>
<span class="go">11</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.clearstamp">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clearstamp</code><span class="sig-paren">(</span><em class="sig-param">stampid</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearstamp" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>stampid</strong> -- 一个整型数，必须是之前 <a class="reference internal" href="#turtle.stamp" title="turtle.stamp"><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code></a> 调用的返回值</p>
</dd>
</dl>
<p>删除 <em>stampid</em> 指定的印章。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(150.00,-0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;blue&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">astamp</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(200.00,-0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamp</span><span class="p">(</span><span class="n">astamp</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(200.00,-0.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.clearstamps">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clearstamps</code><span class="sig-paren">(</span><em class="sig-param">n=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearstamps" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>n</strong> -- 一个整型数 (或 <code class="docutils literal notranslate"><span class="pre">None</span></code>)</p>
</dd>
</dl>
<p>删除全部或前/后 <em>n</em> 个海龟印章。如果 <em>n</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 则删除全部印章，如果 <em>n</em> &gt; 0 则删除前 <em>n</em> 个印章，否则如果 <em>n</em> &lt; 0 则删除后 <em>n</em> 个印章。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">turtle</span><span class="o">.</span><span class="n">stamp</span><span class="p">();</span> <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="go">13</span>
<span class="go">14</span>
<span class="go">15</span>
<span class="go">16</span>
<span class="go">17</span>
<span class="go">18</span>
<span class="go">19</span>
<span class="go">20</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">clearstamps</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.undo">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">undo</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.undo" title="永久链接至目标">¶</a></dt>
<dd><p>撤消 (或连续撤消) 最近的一个 (或多个) 海龟动作。可撤消的次数由撤消缓冲区的大小决定。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">);</span> <span class="n">turtle</span><span class="o">.</span><span class="n">lt</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">turtle</span><span class="o">.</span><span class="n">undo</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.speed">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">speed</code><span class="sig-paren">(</span><em class="sig-param">speed=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.speed" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>speed</strong> -- 一个 0..10 范围内的整型数或速度字符串 (见下)</p>
</dd>
</dl>
<p>设置海龟移动的速度为 0..10 表示的整型数值。如未指定参数则返回当前速度。</p>
<p>如果输入数值大于 10 或小于 0.5 则速度设为 0。速度字符串与速度值的对应关系如下:</p>
<ul class="simple">
<li><p>&quot;fastest&quot;:  0 最快</p></li>
<li><p>&quot;fast&quot;:  10 快</p></li>
<li><p>&quot;normal&quot;:  6 正常</p></li>
<li><p>&quot;slow&quot;:  3 慢</p></li>
<li><p>&quot;slowest&quot;:  1 最慢</p></li>
</ul>
<p>速度值从 1 到 10，画线和海龟转向的动画效果逐级加快。</p>
<p>注意: <em>speed</em> = 0 表示 <em>没有</em> 动画效果。forward/back 将使海龟向前/向后跳跃，同样的 left/right 将使海龟立即改变朝向。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">(</span><span class="s1">&#39;normal&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
<span class="go">6</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">speed</span><span class="p">()</span>
<span class="go">9</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="tell-turtle-s-state">
<h3>获取海龟的状态<a class="headerlink" href="#tell-turtle-s-state" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.position">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">position</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.position" title="永久链接至目标">¶</a></dt>
<dt id="turtle.pos">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pos</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pos" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟当前的坐标 (x,y) (为 <a class="reference internal" href="#turtle.Vec2D" title="turtle.Vec2D"><code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code></a> 矢量类对象)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="go">(440.00,-0.00)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.towards">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">towards</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.towards" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> -- 一个数值或数值对/矢量，或一个海龟实例</p></li>
<li><p><strong>y</strong> -- 一个数值——如果 <em>x</em> 是一个数值，否则为 <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
</ul>
</dd>
</dl>
<p>从海龟位置到由 (x,y)，矢量或另一海龟对应位置的连线的夹角。此数值依赖于海龟初始朝向  - 由 &quot;standard&quot;/&quot;world&quot; 或 &quot;logo&quot; 模式设置所决定)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">towards</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">)</span>
<span class="go">225.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.xcor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">xcor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.xcor" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟的 x 坐标。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">()</span>
<span class="go">(64.28,76.60)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">xcor</span><span class="p">(),</span> <span class="mi">5</span><span class="p">))</span>
<span class="go">64.27876</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.ycor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">ycor</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ycor" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟的 y 坐标。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pos</span><span class="p">())</span>
<span class="go">(50.00,86.60)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">ycor</span><span class="p">(),</span> <span class="mi">5</span><span class="p">))</span>
<span class="go">86.60254</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.heading">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">heading</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.heading" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟当前的朝向 (数值依赖于海龟模式参见 <a class="reference internal" href="#turtle.mode" title="turtle.mode"><code class="xref py py-func docutils literal notranslate"><span class="pre">mode()</span></code></a>)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">67</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">67.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.distance">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">distance</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.distance" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x</strong> -- 一个数值或数值对/矢量，或一个海龟实例</p></li>
<li><p><strong>y</strong> -- 一个数值——如果 <em>x</em> 是一个数值，否则为 <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
</ul>
</dd>
</dl>
<p>返回从海龟位置到由 (x,y)，适量或另一海龟对应位置的单位距离。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span><span class="mi">40</span><span class="p">)</span>
<span class="go">50.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">((</span><span class="mi">30</span><span class="p">,</span><span class="mi">40</span><span class="p">))</span>
<span class="go">50.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">joe</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">joe</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="mi">77</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">distance</span><span class="p">(</span><span class="n">joe</span><span class="p">)</span>
<span class="go">77.0</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="settings-for-measurement">
<h3>度量单位设置<a class="headerlink" href="#settings-for-measurement" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.degrees">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">degrees</code><span class="sig-paren">(</span><em class="sig-param">fullcircle=360.0</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.degrees" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>fullcircle</strong> -- 一个数值</p>
</dd>
</dl>
<p>设置角度的度量单位，即设置一个圆周为多少 &quot;度&quot;。默认值为 360 度。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">90.0</span>

<span class="go">Change angle measurement unit to grad (also known as gon,</span>
<span class="go">grade, or gradian and equals 1/100-th of the right angle.)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">degrees</span><span class="p">(</span><span class="mf">400.0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">100.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">degrees</span><span class="p">(</span><span class="mi">360</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">90.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.radians">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">radians</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.radians" title="永久链接至目标">¶</a></dt>
<dd><p>设置角度的度量单位为弧度。其值等于 <code class="docutils literal notranslate"><span class="pre">degrees(2*math.pi)</span></code>。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">90.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">radians</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">1.5707963267948966</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="pen-control">
<h3>画笔控制<a class="headerlink" href="#pen-control" title="永久链接至标题">¶</a></h3>
<div class="section" id="drawing-state">
<h4>绘图状态<a class="headerlink" href="#drawing-state" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.pendown">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pendown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pendown" title="永久链接至目标">¶</a></dt>
<dt id="turtle.pd">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pd</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pd" title="永久链接至目标">¶</a></dt>
<dt id="turtle.down">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">down</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.down" title="永久链接至目标">¶</a></dt>
<dd><p>画笔落下 -- 移动时将画线。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.penup">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">penup</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.penup" title="永久链接至目标">¶</a></dt>
<dt id="turtle.pu">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pu</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pu" title="永久链接至目标">¶</a></dt>
<dt id="turtle.up">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">up</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.up" title="永久链接至目标">¶</a></dt>
<dd><p>画笔抬起 -- 移动时不画线。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.pensize">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pensize</code><span class="sig-paren">(</span><em class="sig-param">width=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pensize" title="永久链接至目标">¶</a></dt>
<dt id="turtle.width">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">width</code><span class="sig-paren">(</span><em class="sig-param">width=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.width" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>width</strong> -- 一个正数值</p>
</dd>
</dl>
<p>设置线条的粗细为 <em>width</em> 或返回该值。如果 resizemode 设为 &quot;auto&quot; 并且 turtleshape 为多边形，该多边形也以同样组细的线条绘制。如未指定参数，则返回当前的 pensize。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>   <span class="c1"># from here on lines of width 10 are drawn</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.pen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pen</code><span class="sig-paren">(</span><em class="sig-param">pen=None</em>, <em class="sig-param">**pendict</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pen" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>pen</strong> -- 一个包含部分或全部下列键的字典</p></li>
<li><p><strong>pendict</strong> -- 一个或多个以下列键为关键字的关键字参数</p></li>
</ul>
</dd>
</dl>
<p>返回或设置画笔的属性，以一个包含以下键值对的 &quot;画笔字典&quot; 表示:</p>
<ul class="simple">
<li><p>&quot;shown&quot;: True/False</p></li>
<li><p>&quot;pendown&quot;: True/False</p></li>
<li><p>&quot;pencolor&quot;: 颜色字符串或颜色元组</p></li>
<li><p>&quot;fillcolor&quot;: 颜色字符串或颜色元组</p></li>
<li><p>&quot;pensize&quot;: 正数值</p></li>
<li><p>&quot;speed&quot;: 0..10 范围内的数值</p></li>
<li><p>&quot;resizemode&quot;: &quot;auto&quot; 或 &quot;user&quot; 或 &quot;noresize&quot;</p></li>
<li><p>&quot;stretchfactor&quot;: (正数值, 正数值)</p></li>
<li><p>&quot;outline&quot;: 正数值</p></li>
<li><p>&quot;tilt&quot;: 数值</p></li>
</ul>
<p>此字典可作为后续调用 <a class="reference internal" href="#turtle.pen" title="turtle.pen"><code class="xref py py-func docutils literal notranslate"><span class="pre">pen()</span></code></a> 时的参数，以恢复之前的画笔状态。另外还可将这些属性作为关键词参数提交。使用此方式可以用一条语句设置画笔的多个属性。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">(</span><span class="n">fillcolor</span><span class="o">=</span><span class="s2">&quot;black&quot;</span><span class="p">,</span> <span class="n">pencolor</span><span class="o">=</span><span class="s2">&quot;red&quot;</span><span class="p">,</span> <span class="n">pensize</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<span class="go">[(&#39;fillcolor&#39;, &#39;black&#39;), (&#39;outline&#39;, 1), (&#39;pencolor&#39;, &#39;red&#39;),</span>
<span class="go"> (&#39;pendown&#39;, True), (&#39;pensize&#39;, 10), (&#39;resizemode&#39;, &#39;noresize&#39;),</span>
<span class="go"> (&#39;shearfactor&#39;, 0.0), (&#39;shown&#39;, True), (&#39;speed&#39;, 9),</span>
<span class="go"> (&#39;stretchfactor&#39;, (1.0, 1.0)), (&#39;tilt&#39;, 0.0)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">penstate</span><span class="o">=</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;yellow&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())[:</span><span class="mi">3</span><span class="p">]</span>
<span class="go">[(&#39;fillcolor&#39;, &#39;&#39;), (&#39;outline&#39;, 1), (&#39;pencolor&#39;, &#39;yellow&#39;)]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">(</span><span class="n">penstate</span><span class="p">,</span> <span class="n">fillcolor</span><span class="o">=</span><span class="s2">&quot;green&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">sorted</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">pen</span><span class="p">()</span><span class="o">.</span><span class="n">items</span><span class="p">())[:</span><span class="mi">3</span><span class="p">]</span>
<span class="go">[(&#39;fillcolor&#39;, &#39;green&#39;), (&#39;outline&#39;, 1), (&#39;pencolor&#39;, &#39;red&#39;)]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.isdown">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">isdown</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.isdown" title="永久链接至目标">¶</a></dt>
<dd><p>如果画笔落下返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>，如果画笔抬起返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">isdown</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pendown</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">isdown</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="color-control">
<h4>颜色控制<a class="headerlink" href="#color-control" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.pencolor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">pencolor</code><span class="sig-paren">(</span><em class="sig-param">*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.pencolor" title="永久链接至目标">¶</a></dt>
<dd><p>返回或设置画笔颜色。</p>
<p>允许以下四种输入格式:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">pencolor()</span></code></dt><dd><p>返回以颜色描述字符串或元组 (见示例) 表示的当前画笔颜色。可用作其他 color/pencolor/fillcolor 调用的输入。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">pencolor(colorstring)</span></code></dt><dd><p>设置画笔颜色为 <em>colorstring</em> 指定的 Tk 颜色描述字符串，例如 <code class="docutils literal notranslate"><span class="pre">&quot;red&quot;</span></code>、<code class="docutils literal notranslate"><span class="pre">&quot;yellow&quot;</span></code> 或 <code class="docutils literal notranslate"><span class="pre">&quot;#33cc8c&quot;</span></code>。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">pencolor((r,</span> <span class="pre">g,</span> <span class="pre">b))</span></code></dt><dd><p>设置画笔颜色为以 <em>r</em>, <em>g</em>, <em>b</em> 元组表示的 RGB 颜色。<em>r</em>, <em>g</em>, <em>b</em> 的取值范围应为 0..colormode，colormode 的值为 1.0 或 255 (参见 <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>)。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">pencolor(r,</span> <span class="pre">g,</span> <span class="pre">b)</span></code></dt><dd><blockquote>
<div><p>设置画笔颜色为以 <em>r</em>, <em>g</em>, <em>b</em> 表示的 RGB 颜色。<em>r</em>, <em>g</em>, <em>b</em> 的取值范围应为 0..colormode。</p>
</div></blockquote>
<p>如果 turtleshape 为多边形，该多边形轮廓也以新设置的画笔颜色绘制。</p>
</dd>
</dl>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">colormode</span><span class="p">()</span>
<span class="go">1.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">&#39;red&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="s2">&quot;brown&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">&#39;brown&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">tup</span> <span class="o">=</span> <span class="p">(</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.55</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="n">tup</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">(0.2, 0.8, 0.5490196078431373)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">colormode</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">(51.0, 204.0, 140.0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="s1">&#39;#32c18f&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">(50.0, 193.0, 143.0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.fillcolor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">fillcolor</code><span class="sig-paren">(</span><em class="sig-param">*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.fillcolor" title="永久链接至目标">¶</a></dt>
<dd><p>返回或设置填充颜色。</p>
<p>允许以下四种输入格式:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor()</span></code></dt><dd><p>返回以颜色描述字符串或元组 (见示例) 表示的当前填充颜色。可用作其他 color/pencolor/fillcolor 调用的输入。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor(colorstring)</span></code></dt><dd><p>设置填充颜色为 <em>colorstring</em> 指定的 Tk 颜色描述字符串，例如 <code class="docutils literal notranslate"><span class="pre">&quot;red&quot;</span></code>、<code class="docutils literal notranslate"><span class="pre">&quot;yellow&quot;</span></code> 或 <code class="docutils literal notranslate"><span class="pre">&quot;#33cc8c&quot;</span></code>。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor((r,</span> <span class="pre">g,</span> <span class="pre">b))</span></code></dt><dd><p>设置填充颜色为以 <em>r</em>, <em>g</em>, <em>b</em> 元组表示的 RGB 颜色。<em>r</em>, <em>g</em>, <em>b</em> 的取值范围应为 0..colormode，colormode 的值为 1.0 或 255 (参见 <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>)。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">fillcolor(r,</span> <span class="pre">g,</span> <span class="pre">b)</span></code></dt><dd><blockquote>
<div><p>设置填充颜色为 <em>r</em>, <em>g</em>, <em>b</em> 表示的 RGB 颜色。<em>r</em>, <em>g</em>, <em>b</em> 的取值范围应为 0..colormode。</p>
</div></blockquote>
<p>如果 turtleshape 为多边形，该多边形内部也以新设置的填充颜色填充。</p>
</dd>
</dl>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">&quot;violet&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
<span class="go">&#39;violet&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">()</span>
<span class="go">(50.0, 193.0, 143.0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">((</span><span class="mi">50</span><span class="p">,</span> <span class="mi">193</span><span class="p">,</span> <span class="mi">143</span><span class="p">))</span>  <span class="c1"># Integers, not floats</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
<span class="go">(50.0, 193.0, 143.0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s1">&#39;#ffffff&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">()</span>
<span class="go">(255.0, 255.0, 255.0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.color">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">color</code><span class="sig-paren">(</span><em class="sig-param">*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.color" title="永久链接至目标">¶</a></dt>
<dd><p>返回或设置画笔颜色和填充颜色。</p>
<p>允许多种输入格式。使用如下 0 至 3 个参数:</p>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">color()</span></code></dt><dd><p>返回以一对颜色描述字符串或元组表示的当前画笔颜色和填充颜色，两者可分别由 <a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a> 和 <a class="reference internal" href="#turtle.fillcolor" title="turtle.fillcolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">fillcolor()</span></code></a> 返回。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">color(colorstring)</span></code>, <code class="docutils literal notranslate"><span class="pre">color((r,g,b))</span></code>, <code class="docutils literal notranslate"><span class="pre">color(r,g,b)</span></code></dt><dd><p>输入格式与 <a class="reference internal" href="#turtle.pencolor" title="turtle.pencolor"><code class="xref py py-func docutils literal notranslate"><span class="pre">pencolor()</span></code></a> 相同，同时设置填充颜色和画笔颜色为指定的值。</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">color(colorstring1,</span> <span class="pre">colorstring2)</span></code>, <code class="docutils literal notranslate"><span class="pre">color((r1,g1,b1),</span> <span class="pre">(r2,g2,b2))</span></code></dt><dd><blockquote>
<div><p>相当于 <code class="docutils literal notranslate"><span class="pre">pencolor(colorstring1)</span></code> 加 <code class="docutils literal notranslate"><span class="pre">fillcolor(colorstring2)</span></code>，使用其他输入格式的方法也与之类似。</p>
</div></blockquote>
<p>如果 turtleshape 为多边形，该多边形轮廓与填充也使用新设置的颜色。</p>
</dd>
</dl>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;red&quot;</span><span class="p">,</span> <span class="s2">&quot;green&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">()</span>
<span class="go">(&#39;red&#39;, &#39;green&#39;)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;#285078&quot;</span><span class="p">,</span> <span class="s2">&quot;#a0c8f0&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">color</span><span class="p">()</span>
<span class="go">((40.0, 80.0, 120.0), (160.0, 200.0, 240.0))</span>
</pre></div>
</div>
</dd></dl>

<p>另参见: Screen 方法 <a class="reference internal" href="#turtle.colormode" title="turtle.colormode"><code class="xref py py-func docutils literal notranslate"><span class="pre">colormode()</span></code></a>。</p>
</div>
<div class="section" id="filling">
<h4>填充<a class="headerlink" href="#filling" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.filling">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">filling</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.filling" title="永久链接至目标">¶</a></dt>
<dd><p>返回填充状态 (填充为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，否则为 <code class="docutils literal notranslate"><span class="pre">False</span></code>)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_fill</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">if</span> <span class="n">turtle</span><span class="o">.</span><span class="n">filling</span><span class="p">():</span>
<span class="gp">... </span>   <span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">... </span><span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>   <span class="n">turtle</span><span class="o">.</span><span class="n">pensize</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.begin_fill">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">begin_fill</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.begin_fill" title="永久链接至目标">¶</a></dt>
<dd><p>在绘制要填充的形状之前调用。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.end_fill">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">end_fill</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.end_fill" title="永久链接至目标">¶</a></dt>
<dd><p>填充上次调用 <a class="reference internal" href="#turtle.begin_fill" title="turtle.begin_fill"><code class="xref py py-func docutils literal notranslate"><span class="pre">begin_fill()</span></code></a> 之后绘制的形状。</p>
<p>自相交多边形或多个形状间的重叠区域是否填充取决于操作系统的图形引擎、重叠的类型以及重叠的层数。 例如上面的 Turtle 多芒星可能会全部填充为黄色，也可能会有一些白色区域。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;black&quot;</span><span class="p">,</span> <span class="s2">&quot;red&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_fill</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">circle</span><span class="p">(</span><span class="mi">80</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">end_fill</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="more-drawing-control">
<h4>更多绘图控制<a class="headerlink" href="#more-drawing-control" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.reset">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.reset" title="永久链接至目标">¶</a></dt>
<dd><p>从屏幕中删除海龟的绘图，海龟回到原点并设置所有变量为默认值。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="o">-</span><span class="mi">22</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,-22.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">100.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">position</span><span class="p">()</span>
<span class="go">(0.00,0.00)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">heading</span><span class="p">()</span>
<span class="go">0.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.clear">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clear" title="永久链接至目标">¶</a></dt>
<dd><p>从屏幕中删除指定海龟的绘图。不移动海龟。海龟的状态和位置以及其他海龟的绘图不受影响。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.write">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">write</code><span class="sig-paren">(</span><em class="sig-param">arg</em>, <em class="sig-param">move=False</em>, <em class="sig-param">align=&quot;left&quot;</em>, <em class="sig-param">font=(&quot;Arial&quot;</em>, <em class="sig-param">8</em>, <em class="sig-param">&quot;normal&quot;)</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.write" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>arg</strong> -- 要书写到 TurtleScreen 的对象</p></li>
<li><p><strong>move</strong> -- True/False</p></li>
<li><p><strong>align</strong> -- 字符串 &quot;left&quot;, &quot;center&quot; 或 &quot;right&quot;</p></li>
<li><p><strong>font</strong> -- 一个三元组 (fontname, fontsize, fonttype)</p></li>
</ul>
</dd>
</dl>
<p>书写文本 - <em>arg</em> 指定的字符串 - 到当前海龟位置，<em>align</em> 指定对齐方式 (&quot;left&quot;, &quot;center&quot; 或 right&quot;)，font 指定字体。如果 <em>move</em> 为 True，画笔会移动到文本的右下角。默认 <em>move</em> 为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Home = &quot;</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="n">align</span><span class="o">=</span><span class="s2">&quot;center&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">write</span><span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),</span> <span class="kc">True</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>
<div class="section" id="turtle-state">
<h3>海龟状态<a class="headerlink" href="#turtle-state" title="永久链接至标题">¶</a></h3>
<div class="section" id="visibility">
<h4>可见性<a class="headerlink" href="#visibility" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.hideturtle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">hideturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.hideturtle" title="永久链接至目标">¶</a></dt>
<dt id="turtle.ht">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">ht</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ht" title="永久链接至目标">¶</a></dt>
<dd><p>使海龟不可见。当你绘制复杂图形时这是个好主意，因为隐藏海龟可显著加快绘制速度。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">hideturtle</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.showturtle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">showturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.showturtle" title="永久链接至目标">¶</a></dt>
<dt id="turtle.st">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">st</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.st" title="永久链接至目标">¶</a></dt>
<dd><p>使海龟可见。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">showturtle</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.isvisible">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">isvisible</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.isvisible" title="永久链接至目标">¶</a></dt>
<dd><p>如果海龟显示返回 <code class="docutils literal notranslate"><span class="pre">True</span></code>，如果海龟隐藏返回 <code class="docutils literal notranslate"><span class="pre">False</span></code>。</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">hideturtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">isvisible</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">showturtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">isvisible</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="appearance">
<h4>外观<a class="headerlink" href="#appearance" title="永久链接至标题">¶</a></h4>
<dl class="function">
<dt id="turtle.shape">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">shape</code><span class="sig-paren">(</span><em class="sig-param">name=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shape" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>name</strong> -- 一个有效的形状名字符串</p>
</dd>
</dl>
<p>设置海龟形状为 <em>name</em> 指定的形状名，如未指定形状名则返回当前的形状名。<em>name</em> 指定的形状名应存在于 TurtleScreen 的 shape 字典中。多边形的形状初始时有以下几种: &quot;arrow&quot;, &quot;turtle&quot;, &quot;circle&quot;, &quot;square&quot;, &quot;triangle&quot;, &quot;classic&quot;。要了解如何处理形状请参看 Screen 方法 <a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a>。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">()</span>
<span class="go">&#39;classic&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;turtle&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">()</span>
<span class="go">&#39;turtle&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.resizemode">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">resizemode</code><span class="sig-paren">(</span><em class="sig-param">rmode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.resizemode" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>rmode</strong> -- 字符串 &quot;auto&quot;, &quot;user&quot;, &quot;noresize&quot; 其中之一</p>
</dd>
</dl>
<p>设置大小调整模式为以下值之一: &quot;auto&quot;, &quot;user&quot;, &quot;noresize&quot;。如未指定 <em>rmode</em> 则返回当前的大小调整模式。不同的大小调整模式的效果如下:</p>
<ul class="simple">
<li><p>&quot;auto&quot;: 根据画笔粗细值调整海龟的外观。</p></li>
<li><p>&quot;user&quot;: 根据拉伸因子和轮廓宽度 (outline) 值调整海龟的外观，两者是由 <a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a> 设置的。</p></li>
<li><p>&quot;noresize&quot;: 不调整海龟的外观大小。</p></li>
</ul>
<p>大小调整模式 (&quot;user&quot;) 会在 <a class="reference internal" href="#turtle.shapesize" title="turtle.shapesize"><code class="xref py py-func docutils literal notranslate"><span class="pre">shapesize()</span></code></a> 带参数调用时生效。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">()</span>
<span class="go">&#39;noresize&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">(</span><span class="s2">&quot;auto&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">()</span>
<span class="go">&#39;auto&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.shapesize">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">shapesize</code><span class="sig-paren">(</span><em class="sig-param">stretch_wid=None</em>, <em class="sig-param">stretch_len=None</em>, <em class="sig-param">outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shapesize" title="永久链接至目标">¶</a></dt>
<dt id="turtle.turtlesize">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">turtlesize</code><span class="sig-paren">(</span><em class="sig-param">stretch_wid=None</em>, <em class="sig-param">stretch_len=None</em>, <em class="sig-param">outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.turtlesize" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>stretch_wid</strong> -- 正数值</p></li>
<li><p><strong>stretch_len</strong> -- 正数值</p></li>
<li><p><strong>outline</strong> -- 正数值</p></li>
</ul>
</dd>
</dl>
<p>返回或设置画笔的属性 x/y-拉伸因子和/或轮廓。设置大小调整模式为 &quot;user&quot;。当且仅当大小调整模式设为 &quot;user&quot; 时海龟会基于其拉伸因子调整外观: <em>stretch_wid</em> 为垂直于其朝向的宽度拉伸因子，<em>stretch_len</em> 为平等于其朝向的长度拉伸因子，决定形状轮廓线的粗细。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
<span class="go">(1.0, 1.0, 1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">resizemode</span><span class="p">(</span><span class="s2">&quot;user&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">12</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
<span class="go">(5, 5, 12)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="n">outline</span><span class="o">=</span><span class="mi">8</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">()</span>
<span class="go">(5, 5, 8)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.shearfactor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">shearfactor</code><span class="sig-paren">(</span><em class="sig-param">shear=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shearfactor" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>shear</strong> -- 数值 (可选)</p>
</dd>
</dl>
<p>设置或返回当前的剪切因子。根据 share 指定的剪切因子即剪切角度的切线来剪切海龟形状。<em>不</em> 改变海龟的朝向 (移动方向)。如未指定 shear 参数: 返回当前的剪切因子即剪切角度的切线，与海龟朝向平行的线条将被剪切。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;circle&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">()</span>
<span class="go">0.5</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.tilt">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">tilt</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tilt" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>angle</strong> -- 一个数值</p>
</dd>
</dl>
<p>海龟形状自其当前的倾角转动 <em>angle</em> 指定的角度，但 <em>不</em> 改变海龟的朝向 (移动方向)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;circle&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.settiltangle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">settiltangle</code><span class="sig-paren">(</span><em class="sig-param">angle</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.settiltangle" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>angle</strong> -- 一个数值</p>
</dd>
</dl>
<p>旋转海龟形状使其指向 <em>angle</em> 指定的方向，忽略其当前的倾角，<em>不</em> 改变海龟的朝向 (移动方向)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;circle&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">settiltangle</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">settiltangle</span><span class="p">(</span><span class="o">-</span><span class="mi">45</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
</pre></div>
</div>
<div class="deprecated">
<p><span class="versionmodified deprecated">3.1 版后已移除.</span></p>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.tiltangle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">tiltangle</code><span class="sig-paren">(</span><em class="sig-param">angle=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tiltangle" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>angle</strong> -- 一个数值 (可选)</p>
</dd>
</dl>
<p>设置或返回当前的倾角。如果指定 angle 则旋转海龟形状使其指向 angle 指定的方向，忽略其当前的倾角。<em>不</em> 改变海龟的朝向 (移动方向)。如果未指定 angle: 返回当前的倾角，即海龟形状的方向和海龟朝向 (移动方向) 之间的夹角。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;circle&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">tilt</span><span class="p">(</span><span class="mi">45</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">tiltangle</span><span class="p">()</span>
<span class="go">45.0</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.shapetransform">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">shapetransform</code><span class="sig-paren">(</span><em class="sig-param">t11=None</em>, <em class="sig-param">t12=None</em>, <em class="sig-param">t21=None</em>, <em class="sig-param">t22=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.shapetransform" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>t11</strong> -- 一个数值 (可选)</p></li>
<li><p><strong>t12</strong> -- 一个数值 (可选)</p></li>
<li><p><strong>t21</strong> -- 一个数值 (可选)</p></li>
<li><p><strong>t12</strong> -- 一个数值 (可选)</p></li>
</ul>
</dd>
</dl>
<p>设置或返回海龟形状的当前变形矩阵。</p>
<p>如不指定任何矩阵元素，则返回以4元素元组表示的变形矩阵。否则使用指定元素设置变形矩阵改变海龟形状，矩阵第一排的值为 t11, t12，第二排的值为 t21, t22。行列式 t11 * t22 - t12 * t21 的值不能为零，否则会出错。根据指定的矩阵修改拉伸因子，剪切因子和倾角。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;square&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapesize</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shearfactor</span><span class="p">(</span><span class="o">-</span><span class="mf">0.5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapetransform</span><span class="p">()</span>
<span class="go">(4.0, -1.0, -0.0, 2.0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.get_shapepoly">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">get_shapepoly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.get_shapepoly" title="永久链接至目标">¶</a></dt>
<dd><p>返回以坐标值对元组表示的当前形状多边形。这可以用于定义一个新形状或一个复合形状的多个组成部分。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;square&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">shapetransform</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">get_shapepoly</span><span class="p">()</span>
<span class="go">((50, -20), (30, 20), (-50, 20), (-30, -20))</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>
<div class="section" id="using-events">
<h3>使用事件<a class="headerlink" href="#using-events" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.onclick">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onclick</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">btn=1</em>, <em class="sig-param">add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onclick" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个函数，调用时将传入两个参数表示在画布上点击的坐标。</p></li>
<li><p><strong>btn</strong> -- 鼠标按钮编号，默认值为 1 (鼠标左键)</p></li>
<li><p><strong>add</strong> -- <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code> -- 如为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则将添加一个新绑定，否则将取代先前的绑定</p></li>
</ul>
</dd>
</dl>
<p>将 <em>fun</em> 指定的函数绑定到鼠标点击此海龟事件。如果 <em>fun</em> 值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则移除现有的绑定。以下为使用匿名海龟即过程式的示例:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">turn</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">left</span><span class="p">(</span><span class="mi">180</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">onclick</span><span class="p">(</span><span class="n">turn</span><span class="p">)</span>  <span class="c1"># Now clicking into the turtle will turn it.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">onclick</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>  <span class="c1"># event-binding will be removed</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.onrelease">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onrelease</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">btn=1</em>, <em class="sig-param">add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onrelease" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个函数，调用时将传入两个参数表示在画布上点击的坐标。</p></li>
<li><p><strong>btn</strong> -- 鼠标按钮编号，默认值为 1 (鼠标左键)</p></li>
<li><p><strong>add</strong> -- <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code> -- 如为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则将添加一个新绑定，否则将取代先前的绑定</p></li>
</ul>
</dd>
</dl>
<p>将 <em>fun</em> 指定的函数绑定到在此海龟上释放鼠标按键事件。如果 <em>fun</em> 值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则移除现有的绑定。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">MyTurtle</span><span class="p">(</span><span class="n">Turtle</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">glow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">&quot;red&quot;</span><span class="p">)</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">unglow</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">x</span><span class="p">,</span><span class="n">y</span><span class="p">):</span>
<span class="gp">... </span>        <span class="bp">self</span><span class="o">.</span><span class="n">fillcolor</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span> <span class="o">=</span> <span class="n">MyTurtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">glow</span><span class="p">)</span>     <span class="c1"># clicking on turtle turns fillcolor red,</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">onrelease</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">unglow</span><span class="p">)</span> <span class="c1"># releasing turns it to transparent.</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.ondrag">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">ondrag</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">btn=1</em>, <em class="sig-param">add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ondrag" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个函数，调用时将传入两个参数表示在画布上点击的坐标。</p></li>
<li><p><strong>btn</strong> -- 鼠标按钮编号，默认值为 1 (鼠标左键)</p></li>
<li><p><strong>add</strong> -- <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code> -- 如为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则将添加一个新绑定，否则将取代先前的绑定</p></li>
</ul>
</dd>
</dl>
<p>将 <em>fun</em> 指定的函数绑定到在此海龟上移动鼠标事件。如果 <em>fun</em> 值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则移除现有的绑定。</p>
<p>注: 在海龟上移动鼠标事件之前应先发生在此海龟上点击鼠标事件。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">ondrag</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">)</span>
</pre></div>
</div>
<p>在此之后点击并拖动海龟可在屏幕上手绘线条 (如果画笔为落下)。</p>
</dd></dl>

</div>
<div class="section" id="special-turtle-methods">
<h3>特殊海龟方法<a class="headerlink" href="#special-turtle-methods" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.begin_poly">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">begin_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.begin_poly" title="永久链接至目标">¶</a></dt>
<dd><p>开始记录多边形的顶点。当前海龟位置为多边形的第一个顶点。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.end_poly">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">end_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.end_poly" title="永久链接至目标">¶</a></dt>
<dd><p>停止记录多边形的顶点。当前海龟位置为多边形的最后一个顶点。它将连线到第一个顶点。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.get_poly">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">get_poly</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.get_poly" title="永久链接至目标">¶</a></dt>
<dd><p>返回最新记录的多边形。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">home</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">begin_poly</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">100</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">20</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">left</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">end_poly</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">get_poly</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">register_shape</span><span class="p">(</span><span class="s2">&quot;myFavouriteShape&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.clone">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clone</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clone" title="永久链接至目标">¶</a></dt>
<dd><p>创建并返回海龟的克隆体，具有相同的位置、朝向和海龟属性。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mick</span> <span class="o">=</span> <span class="n">Turtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">joe</span> <span class="o">=</span> <span class="n">mick</span><span class="o">.</span><span class="n">clone</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.getturtle">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">getturtle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getturtle" title="永久链接至目标">¶</a></dt>
<dt id="turtle.getpen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">getpen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getpen" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟对象自身。唯一合理的用法: 作为一个函数来返回 &quot;匿名海龟&quot;:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pet</span> <span class="o">=</span> <span class="n">getturtle</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pet</span><span class="o">.</span><span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">pet</span>
<span class="go">&lt;turtle.Turtle object at 0x...&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.getscreen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">getscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getscreen" title="永久链接至目标">¶</a></dt>
<dd><p>返回作为海龟绘图场所的 <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> 类对象。该对象将可调用 TurtleScreen 方法。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ts</span> <span class="o">=</span> <span class="n">turtle</span><span class="o">.</span><span class="n">getscreen</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ts</span>
<span class="go">&lt;turtle._Screen object at 0x...&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ts</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">&quot;pink&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.setundobuffer">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setundobuffer</code><span class="sig-paren">(</span><em class="sig-param">size</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setundobuffer" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>size</strong> -- 一个整型数值或 <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd>
</dl>
<p>设置或禁用撤消缓冲区。如果 <em>size</em> 为一个整型数则将开辟一个指定大小的空缓冲区。<em>size</em> 表示可使用 <a class="reference internal" href="#turtle.undo" title="turtle.undo"><code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></a> 方法/函数撤消的海龟命令的次数上限。如果 <em>size</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code> 则禁用撤消缓冲区。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">setundobuffer</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.undobufferentries">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">undobufferentries</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.undobufferentries" title="永久链接至目标">¶</a></dt>
<dd><p>返回撤销缓冲区里的条目数。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">while</span> <span class="n">undobufferentries</span><span class="p">():</span>
<span class="gp">... </span>    <span class="n">undo</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="compound-shapes">
<span id="compoundshapes"></span><h3>复合形状<a class="headerlink" href="#compound-shapes" title="永久链接至标题">¶</a></h3>
<p>要使用由多个不同颜色多边形构成的复合海龟形状，你必须明确地使用辅助类 <a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a>，具体步骤如下:</p>
<ol class="arabic">
<li><p>创建一个空 Shape 对象，类型为 &quot;compound&quot;。</p></li>
<li><p>按照需要使用 <code class="xref py py-meth docutils literal notranslate"><span class="pre">addcomponent()</span></code> 方法向此对象添加多个部件。</p>
<p>例如:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Shape</span><span class="p">(</span><span class="s2">&quot;compound&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">poly1</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly1</span><span class="p">,</span> <span class="s2">&quot;red&quot;</span><span class="p">,</span> <span class="s2">&quot;blue&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">poly2</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly2</span><span class="p">,</span> <span class="s2">&quot;blue&quot;</span><span class="p">,</span> <span class="s2">&quot;red&quot;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>接下来将 Shape 对象添加到 Screen 对象的形状列表并使用它:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">register_shape</span><span class="p">(</span><span class="s2">&quot;myshape&quot;</span><span class="p">,</span> <span class="n">s</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">shape</span><span class="p">(</span><span class="s2">&quot;myshape&quot;</span><span class="p">)</span>
</pre></div>
</div>
</li>
</ol>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p><a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a> 类在 <a class="reference internal" href="#turtle.register_shape" title="turtle.register_shape"><code class="xref py py-func docutils literal notranslate"><span class="pre">register_shape()</span></code></a> 方法的内部以多种方式使用。应用程序编写者 <em>只有</em> 在使用上述的复合形状时才需要处理 Shape 类。</p>
</div>
</div>
</div>
<div class="section" id="methods-of-turtlescreen-screen-and-corresponding-functions">
<h2>TurtleScreen/Screen 方法及对应函数<a class="headerlink" href="#methods-of-turtlescreen-screen-and-corresponding-functions" title="永久链接至标题">¶</a></h2>
<p>本节中的大部分示例都使用 TurtleScreen 类的一个实例，命名为 <code class="docutils literal notranslate"><span class="pre">screen</span></code>。</p>
<div class="section" id="window-control">
<h3>窗口控制<a class="headerlink" href="#window-control" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.bgcolor">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">bgcolor</code><span class="sig-paren">(</span><em class="sig-param">*args</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bgcolor" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>args</strong> -- 一个颜色字符串或三个取值范围 0..colormode 内的数值或一个取值范围相同的数值3元组</p>
</dd>
</dl>
<p>设置或返回 TurtleScreen 的背景颜色。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">&quot;orange&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">()</span>
<span class="go">&#39;orange&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">(</span><span class="s2">&quot;#800080&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">()</span>
<span class="go">(128.0, 0.0, 128.0)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.bgpic">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">bgpic</code><span class="sig-paren">(</span><em class="sig-param">picname=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bgpic" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>picname</strong> -- 一个字符串, gif-文件名, <code class="docutils literal notranslate"><span class="pre">&quot;nopic&quot;</span></code>, 或 <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd>
</dl>
<p>设置背景图片或返回当前背景图片名称。如果 <em>picname</em> 为一个文件名，则将相应图片设为背景。如果 <em>picname</em> 为 <code class="docutils literal notranslate"><span class="pre">&quot;nopic&quot;</span></code>，则删除当前背景图片。如果 <em>picname</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则返回当前背景图片文件名。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">()</span>
<span class="go">&#39;nopic&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">(</span><span class="s2">&quot;landscape.gif&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">bgpic</span><span class="p">()</span>
<span class="go">&quot;landscape.gif&quot;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt>
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dt id="turtle.clearscreen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">clearscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.clearscreen" title="永久链接至目标">¶</a></dt>
<dd><p>从中删除所有海龟的全部绘图。将已清空的 TurtleScreen 重置为初始状态: 白色背景，无背景片，无事件绑定并启用追踪。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此 TurtleScreen 方法作为全局函数时只有一个名字 <code class="docutils literal notranslate"><span class="pre">clearscreen</span></code>。全局函数 <code class="docutils literal notranslate"><span class="pre">clear</span></code> 所对应的是 Turtle 方法 <code class="docutils literal notranslate"><span class="pre">clear</span></code>。</p>
</div>
</dd></dl>

<dl class="function">
<dt>
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span></dt>
<dt id="turtle.resetscreen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">resetscreen</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.resetscreen" title="永久链接至目标">¶</a></dt>
<dd><p>重置屏幕上的所有海龟为其初始状态。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此 TurtleScreen 方法作为全局函数时只有一个名字 <code class="docutils literal notranslate"><span class="pre">resetscreen</span></code>。全局函数 <code class="docutils literal notranslate"><span class="pre">reset</span></code> 所对应的是 Turtle 方法 <code class="docutils literal notranslate"><span class="pre">reset</span></code>。</p>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.screensize">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">screensize</code><span class="sig-paren">(</span><em class="sig-param">canvwidth=None</em>, <em class="sig-param">canvheight=None</em>, <em class="sig-param">bg=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.screensize" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>canvwidth</strong> -- 正整型数，以像素表示画布的新宽度值</p></li>
<li><p><strong>canvheight</strong> -- 正整型数，以像素表示画面的新高度值</p></li>
<li><p><strong>bg</strong> -- 颜色字符串或颜色元组，新的背景颜色</p></li>
</ul>
</dd>
</dl>
<p>如未指定任何参数，则返回当前的 (canvaswidth, canvasheight)。否则改变作为海龟绘图场所的画布大小。不改变绘图窗口。要观察画布的隐藏区域，可以使用滚动条。通过此方法可以令之前绘制于画布之外的图形变为可见。</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">()</span>
<span class="go">(400, 300)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">(</span><span class="mi">2000</span><span class="p">,</span><span class="mi">1500</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">screensize</span><span class="p">()</span>
<span class="go">(2000, 1500)</span>
</pre></div>
</div>
<p>也可以用来寻找意外逃走的海龟 ;-)</p>
</dd></dl>

<dl class="function">
<dt id="turtle.setworldcoordinates">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setworldcoordinates</code><span class="sig-paren">(</span><em class="sig-param">llx</em>, <em class="sig-param">lly</em>, <em class="sig-param">urx</em>, <em class="sig-param">ury</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setworldcoordinates" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>llx</strong> -- 一个数值, 画布左下角的 x-坐标</p></li>
<li><p><strong>lly</strong> -- 一个数值, 画布左下角的 y-坐标</p></li>
<li><p><strong>urx</strong> -- 一个数值, 画面右上角的 x-坐标</p></li>
<li><p><strong>ury</strong> -- 一个数值, 画布右上角的 y-坐标</p></li>
</ul>
</dd>
</dl>
<p>设置用户自定义坐标系并在必要时切换模式为 &quot;world&quot;。这会执行一次 <code class="docutils literal notranslate"><span class="pre">screen.reset()</span></code>。如果 &quot;world&quot; 模式已激活，则所有图形将根据新的坐标系重绘。</p>
<p><strong>注意</strong>: 在用户自定义坐标系中，角度可能显得扭曲。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">setworldcoordinates</span><span class="p">(</span><span class="o">-</span><span class="mi">50</span><span class="p">,</span><span class="o">-</span><span class="mf">7.5</span><span class="p">,</span><span class="mi">50</span><span class="p">,</span><span class="mf">7.5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">72</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">left</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">8</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">left</span><span class="p">(</span><span class="mi">45</span><span class="p">);</span> <span class="n">fd</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>   <span class="c1"># a regular octagon</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="animation-control">
<h3>动画控制<a class="headerlink" href="#animation-control" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.delay">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">delay</code><span class="sig-paren">(</span><em class="sig-param">delay=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.delay" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>delay</strong> -- 正整型数</p>
</dd>
</dl>
<p>设置或返回以毫秒数表示的延迟值 <em>delay</em>。(这约等于连续两次画布刷新的间隔时间。) 绘图延迟越长，动画速度越慢。</p>
<p>可选参数:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
<span class="go">10</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">delay</span><span class="p">()</span>
<span class="go">5</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.tracer">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">tracer</code><span class="sig-paren">(</span><em class="sig-param">n=None</em>, <em class="sig-param">delay=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.tracer" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>n</strong> -- 非负整型数</p></li>
<li><p><strong>delay</strong> -- 非负整型数</p></li>
</ul>
</dd>
</dl>
<p>启用/禁用海龟动画并设置刷新图形的延迟时间。如果指定 <em>n</em> 值，则只有每第 n 次屏幕刷新会实际执行。(可被用来加速复杂图形的绘制。) 如果调用时不带参数，则返回当前保存的 n 值。第二个参数设置延迟值 (参见 <a class="reference internal" href="#turtle.delay" title="turtle.delay"><code class="xref py py-func docutils literal notranslate"><span class="pre">delay()</span></code></a>)。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">tracer</span><span class="p">(</span><span class="mi">8</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">dist</span> <span class="o">=</span> <span class="mi">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">200</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">fd</span><span class="p">(</span><span class="n">dist</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">rt</span><span class="p">(</span><span class="mi">90</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">dist</span> <span class="o">+=</span> <span class="mi">2</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.update">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">update</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.update" title="永久链接至目标">¶</a></dt>
<dd><p>执行一次 TurtleScreen 刷新。在禁用追踪时使用。</p>
</dd></dl>

<p>另参见 RawTurtle/Turtle 方法 <a class="reference internal" href="#turtle.speed" title="turtle.speed"><code class="xref py py-func docutils literal notranslate"><span class="pre">speed()</span></code></a>。</p>
</div>
<div class="section" id="using-screen-events">
<h3>使用屏幕事件<a class="headerlink" href="#using-screen-events" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.listen">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">listen</code><span class="sig-paren">(</span><em class="sig-param">xdummy=None</em>, <em class="sig-param">ydummy=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.listen" title="永久链接至目标">¶</a></dt>
<dd><p>设置焦点到 TurtleScreen (以便接收按键事件)。使用两个 Dummy 参数以便能够传递 <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a> 给 onclick 方法。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.onkey">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onkey</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">key</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkey" title="永久链接至目标">¶</a></dt>
<dt id="turtle.onkeyrelease">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onkeyrelease</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">key</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkeyrelease" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个无参数的函数或 <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
<li><p><strong>key</strong> -- 一个字符串: 键 (例如 &quot;a&quot;) 或键标 (例如 &quot;space&quot;)</p></li>
</ul>
</dd>
</dl>
<p>绑定 <em>fun</em> 指定的函数到按键释放事件。如果 <em>fun</em> 值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则移除事件绑定。注: 为了能够注册按键事件，TurtleScreen 必须得到焦点。(参见 method <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a> 方法。)</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
<span class="gp">... </span>    <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">... </span>    <span class="n">lt</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">onkey</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s2">&quot;Up&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">listen</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.onkeypress">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onkeypress</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">key=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onkeypress" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个无参数的函数或 <code class="docutils literal notranslate"><span class="pre">None</span></code></p></li>
<li><p><strong>key</strong> -- 一个字符串: 键 (例如 &quot;a&quot;) 或键标 (例如 &quot;space&quot;)</p></li>
</ul>
</dd>
</dl>
<p>绑定 <em>fun</em> 指定的函数到指定键的按下事件。如未指定键则绑定到任意键的按下事件。注: 为了能够注册按键事件，必须得到焦点。(参见 <a class="reference internal" href="#turtle.listen" title="turtle.listen"><code class="xref py py-func docutils literal notranslate"><span class="pre">listen()</span></code></a> 方法。)</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
<span class="gp">... </span>    <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">onkey</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s2">&quot;Up&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">listen</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt>
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onclick</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">btn=1</em>, <em class="sig-param">add=None</em><span class="sig-paren">)</span></dt>
<dt id="turtle.onscreenclick">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">onscreenclick</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">btn=1</em>, <em class="sig-param">add=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.onscreenclick" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个函数，调用时将传入两个参数表示在画布上点击的坐标。</p></li>
<li><p><strong>btn</strong> -- 鼠标按钮编号，默认值为 1 (鼠标左键)</p></li>
<li><p><strong>add</strong> -- <code class="docutils literal notranslate"><span class="pre">True</span></code> 或 <code class="docutils literal notranslate"><span class="pre">False</span></code> -- 如为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 则将添加一个新绑定，否则将取代先前的绑定</p></li>
</ul>
</dd>
</dl>
<p>绑定 <em>fun</em> 指定的函数到鼠标点击屏幕事件。如果 <em>fun</em> 值为 <code class="docutils literal notranslate"><span class="pre">None</span></code>，则移除现有的绑定。</p>
<p>以下示例使用一个 TurtleScreen 实例 <code class="docutils literal notranslate"><span class="pre">screen</span></code> 和一个 Turtle 实例 turtle:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="n">turtle</span><span class="o">.</span><span class="n">goto</span><span class="p">)</span> <span class="c1"># Subsequently clicking into the TurtleScreen will</span>
<span class="gp">&gt;&gt;&gt; </span>                            <span class="c1"># make the turtle move to the clicked point.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">onclick</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>        <span class="c1"># remove event binding again</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>此 TurtleScreen 方法作为全局函数时只有一个名字 <code class="docutils literal notranslate"><span class="pre">onscreenclick</span></code>。全局函数 <code class="docutils literal notranslate"><span class="pre">onclick</span></code> 所对应的是 Turtle 方法 <code class="docutils literal notranslate"><span class="pre">onclick</span></code>。</p>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.ontimer">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">ontimer</code><span class="sig-paren">(</span><em class="sig-param">fun</em>, <em class="sig-param">t=0</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ontimer" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fun</strong> -- 一个无参数的函数</p></li>
<li><p><strong>t</strong> -- 一个数值 &gt;= 0</p></li>
</ul>
</dd>
</dl>
<p>安装一个计时器，在 <em>t</em> 毫秒后调用 <em>fun</em> 函数。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">running</span> <span class="o">=</span> <span class="kc">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">f</span><span class="p">():</span>
<span class="gp">... </span>    <span class="k">if</span> <span class="n">running</span><span class="p">:</span>
<span class="gp">... </span>        <span class="n">fd</span><span class="p">(</span><span class="mi">50</span><span class="p">)</span>
<span class="gp">... </span>        <span class="n">lt</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span>
<span class="gp">... </span>        <span class="n">screen</span><span class="o">.</span><span class="n">ontimer</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="mi">250</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span><span class="p">()</span>   <span class="c1">### makes the turtle march around</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">running</span> <span class="o">=</span> <span class="kc">False</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.mainloop">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">mainloop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.mainloop" title="永久链接至目标">¶</a></dt>
<dt id="turtle.done">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">done</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.done" title="永久链接至目标">¶</a></dt>
<dd><p>开始事件循环 - 调用 Tkinter 的 mainloop 函数。必须作为一个海龟绘图程序的结束语句。如果一个脚本是在以 -n 模式 (无子进程) 启动的 IDLE 中运行时 <em>不可</em> 使用 - 用于实现海龟绘图的交互功能。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="input-methods">
<h3>输入方法<a class="headerlink" href="#input-methods" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.textinput">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">textinput</code><span class="sig-paren">(</span><em class="sig-param">title</em>, <em class="sig-param">prompt</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.textinput" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>title</strong> -- string</p></li>
<li><p><strong>prompt</strong> -- string</p></li>
</ul>
</dd>
</dl>
<p>弹出一个对话框窗口用来输入一个字符串。形参 title 为对话框窗口的标题，prompt 为一条文本，通常用来提示要输入什么信息。返回输入的字符串。如果对话框被取消则返回 <code class="docutils literal notranslate"><span class="pre">None</span></code>。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">textinput</span><span class="p">(</span><span class="s2">&quot;NIM&quot;</span><span class="p">,</span> <span class="s2">&quot;Name of first player:&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.numinput">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">numinput</code><span class="sig-paren">(</span><em class="sig-param">title</em>, <em class="sig-param">prompt</em>, <em class="sig-param">default=None</em>, <em class="sig-param">minval=None</em>, <em class="sig-param">maxval=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.numinput" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>title</strong> -- string</p></li>
<li><p><strong>prompt</strong> -- string</p></li>
<li><p><strong>default</strong> -- 数值 (可选)</p></li>
<li><p><strong>minval</strong> -- 数值 (可选)</p></li>
<li><p><strong>maxval</strong> -- 数值 (可选)</p></li>
</ul>
</dd>
</dl>
<p>弹出一个对话框窗口用来输入一个数值。title 为对话框窗口的标题，prompt 为一条文本，通常用来描述要输入的数值信息。default: 默认值, minval: 可输入的最小值, maxval: 可输入的最大值。输入数值的必须在指定的 minval .. maxval 范围之内，否则将给出一条提示，对话框保持打开等待修改。返回输入的数值。如果对话框被取消则返回 <code class="docutils literal notranslate"><span class="pre">None</span></code>。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">numinput</span><span class="p">(</span><span class="s2">&quot;Poker&quot;</span><span class="p">,</span> <span class="s2">&quot;Your stakes:&quot;</span><span class="p">,</span> <span class="mi">1000</span><span class="p">,</span> <span class="n">minval</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">maxval</span><span class="o">=</span><span class="mi">10000</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="settings-and-special-methods">
<h3>设置与特殊方法<a class="headerlink" href="#settings-and-special-methods" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.mode">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">mode</code><span class="sig-paren">(</span><em class="sig-param">mode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.mode" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>mode</strong> -- 字符串 &quot;standard&quot;, &quot;logo&quot; 或 &quot;world&quot; 其中之一</p>
</dd>
</dl>
<p>设置海龟模式 (&quot;standard&quot;, &quot;logo&quot; 或 &quot;world&quot;) 并执行重置。如未指定模式则返回当前的模式。</p>
<p>&quot;standard&quot; 模式与旧的 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 兼容。&quot;logo&quot; 模式与大部分 Logo 海龟绘图兼容。&quot;world&quot; 模式使用用户自定义的 &quot;世界坐标系&quot;。<strong>注意</strong>: 在此模式下，如果 <code class="docutils literal notranslate"><span class="pre">x/y</span></code> 单位比率不等于 1 则角度会显得扭曲。</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 21%" />
<col style="width: 45%" />
<col style="width: 34%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>模式</p></th>
<th class="head"><p>初始海龟朝向</p></th>
<th class="head"><p>正数角度</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>&quot;standard&quot;</p></td>
<td><p>朝右 (东)</p></td>
<td><p>逆时针</p></td>
</tr>
<tr class="row-odd"><td><p>&quot;logo&quot;</p></td>
<td><p>朝上 (北)</p></td>
<td><p>顺时针</p></td>
</tr>
</tbody>
</table>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">mode</span><span class="p">(</span><span class="s2">&quot;logo&quot;</span><span class="p">)</span>   <span class="c1"># resets turtle heading to north</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mode</span><span class="p">()</span>
<span class="go">&#39;logo&#39;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.colormode">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">colormode</code><span class="sig-paren">(</span><em class="sig-param">cmode=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.colormode" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>cmode</strong> -- 数值 1.0 或 255 其中之一</p>
</dd>
</dl>
<p>返回颜色模式或将其设为 1.0 或 255。构成颜色三元组的 <em>r</em>, <em>g</em>, <em>b</em> 数值必须在 0..<em>cmode</em> 范围之内。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="mi">240</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">80</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
     <span class="o">...</span>
<span class="gr">TurtleGraphicsError</span>: <span class="n">bad color sequence: (240, 160, 80)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">()</span>
<span class="go">1.0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">(</span><span class="mi">255</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">colormode</span><span class="p">()</span>
<span class="go">255</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">turtle</span><span class="o">.</span><span class="n">pencolor</span><span class="p">(</span><span class="mi">240</span><span class="p">,</span><span class="mi">160</span><span class="p">,</span><span class="mi">80</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.getcanvas">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">getcanvas</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getcanvas" title="永久链接至目标">¶</a></dt>
<dd><p>返回此 TurtleScreen 的 Canvas 对象。供了解 Tkinter 的 Canvas 对象内部机理的人士使用。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">cv</span> <span class="o">=</span> <span class="n">screen</span><span class="o">.</span><span class="n">getcanvas</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">cv</span>
<span class="go">&lt;turtle.ScrolledCanvas object ...&gt;</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.getshapes">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">getshapes</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.getshapes" title="永久链接至目标">¶</a></dt>
<dd><p>返回所有当前可用海龟形状的列表。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">getshapes</span><span class="p">()</span>
<span class="go">[&#39;arrow&#39;, &#39;blank&#39;, &#39;circle&#39;, ..., &#39;turtle&#39;]</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.register_shape">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">register_shape</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">shape=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.register_shape" title="永久链接至目标">¶</a></dt>
<dt id="turtle.addshape">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">addshape</code><span class="sig-paren">(</span><em class="sig-param">name</em>, <em class="sig-param">shape=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.addshape" title="永久链接至目标">¶</a></dt>
<dd><p>调用此函数有三种不同方式:</p>
<ol class="arabic">
<li><p><em>name</em> 为一个 gif 文件的文件名， <em>shape</em> 为 <code class="docutils literal notranslate"><span class="pre">None</span></code>: 安装相应的图像形状。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">register_shape</span><span class="p">(</span><span class="s2">&quot;turtle.gif&quot;</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>当海龟转向时图像形状 <em>不会</em> 转动，因此无法显示海龟的朝向!</p>
</div>
</li>
<li><p><em>name</em> 为指定的字符串，<em>shape</em> 为由坐标值对构成的元组: 安装相应的多边形形状。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">register_shape</span><span class="p">(</span><span class="s2">&quot;triangle&quot;</span><span class="p">,</span> <span class="p">((</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">3</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="o">-</span><span class="mi">3</span><span class="p">)))</span>
</pre></div>
</div>
</li>
<li><p><em>name</em> 为指定的字符串， 为一个 (复合) <a class="reference internal" href="#turtle.Shape" title="turtle.Shape"><code class="xref py py-class docutils literal notranslate"><span class="pre">Shape</span></code></a> 类对象: 安装相应的复合形状。</p></li>
</ol>
<p>将一个海龟形状加入 TurtleScreen 的形状列表。只有这样注册过的形状才能通过执行 <code class="docutils literal notranslate"><span class="pre">shape(shapename)</span></code> 命令来使用。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.turtles">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">turtles</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.turtles" title="永久链接至目标">¶</a></dt>
<dd><p>返回屏幕上的海龟列表。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">turtle</span> <span class="ow">in</span> <span class="n">screen</span><span class="o">.</span><span class="n">turtles</span><span class="p">():</span>
<span class="gp">... </span>    <span class="n">turtle</span><span class="o">.</span><span class="n">color</span><span class="p">(</span><span class="s2">&quot;red&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.window_height">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">window_height</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.window_height" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟窗口的高度。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">window_height</span><span class="p">()</span>
<span class="go">480</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.window_width">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">window_width</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.window_width" title="永久链接至目标">¶</a></dt>
<dd><p>返回海龟窗口的宽度。:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">window_width</span><span class="p">()</span>
<span class="go">640</span>
</pre></div>
</div>
</dd></dl>

</div>
<div class="section" id="methods-specific-to-screen-not-inherited-from-turtlescreen">
<span id="screenspecific"></span><h3>Screen 专有方法, 而非继承自 TurtleScreen<a class="headerlink" href="#methods-specific-to-screen-not-inherited-from-turtlescreen" title="永久链接至标题">¶</a></h3>
<dl class="function">
<dt id="turtle.bye">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">bye</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.bye" title="永久链接至目标">¶</a></dt>
<dd><p>关闭海龟绘图窗口。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.exitonclick">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">exitonclick</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#turtle.exitonclick" title="永久链接至目标">¶</a></dt>
<dd><p>将 bye() 方法绑定到 Screen 上的鼠标点击事件。</p>
<p>如果配置字典中 &quot;using_IDLE&quot; 的值为 <code class="docutils literal notranslate"><span class="pre">False</span></code> (默认值) 则同时进入主事件循环。注: 如果启动 IDLE 时使用了 <code class="docutils literal notranslate"><span class="pre">-n</span></code> 开关 (无子进程)，<code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 中此数值应设为 <code class="docutils literal notranslate"><span class="pre">True</span></code>。在此情况下 IDLE 本身的主事件循环同样会作用于客户脚本。</p>
</dd></dl>

<dl class="function">
<dt id="turtle.setup">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">setup</code><span class="sig-paren">(</span><em class="sig-param">width=_CFG[&quot;width&quot;], height=_CFG[&quot;height&quot;], startx=_CFG[&quot;leftright&quot;], starty=_CFG[&quot;topbottom&quot;]</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.setup" title="永久链接至目标">¶</a></dt>
<dd><p>设置主窗口的大小和位置。默认参数值保存在配置字典中，可通过 <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 文件进行修改。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>width</strong> -- 如为一个整型数值，表示大小为多少像素，如为一个浮点数值，则表示屏幕的占比；默认为屏幕的 50%</p></li>
<li><p><strong>height</strong> -- 如为一个整型数值，表示高度为多少像素，如为一个浮点数值，则表示屏幕的占比；默认为屏幕的 75%</p></li>
<li><p><strong>startx</strong> -- 如为正值，表示初始位置距离屏幕左边缘多少像素，负值表示距离右边缘，<code class="docutils literal notranslate"><span class="pre">None</span></code> 表示窗口水平居中</p></li>
<li><p><strong>starty</strong> -- 如为正值，表示初始位置距离屏幕上边缘多少像素，负值表示距离下边缘，<code class="docutils literal notranslate"><span class="pre">None</span></code> 表示窗口垂直居中</p></li>
</ul>
</dd>
</dl>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">setup</span> <span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">200</span><span class="p">,</span> <span class="n">startx</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">starty</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span>             <span class="c1"># sets window to 200x200 pixels, in upper left of screen</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">setup</span><span class="p">(</span><span class="n">width</span><span class="o">=.</span><span class="mi">75</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">startx</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">starty</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span>             <span class="c1"># sets window to 75% of screen by 50% of screen and centers</span>
</pre></div>
</div>
</dd></dl>

<dl class="function">
<dt id="turtle.title">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">title</code><span class="sig-paren">(</span><em class="sig-param">titlestring</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.title" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>titlestring</strong> -- 一个字符串，显示为海龟绘图窗口的标题栏文本</p>
</dd>
</dl>
<p>设置海龟窗口标题为 <em>titlestring</em> 指定的文本。</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">screen</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s2">&quot;Welcome to the turtle zoo!&quot;</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>
</div>
<div class="section" id="public-classes">
<h2>公共类<a class="headerlink" href="#public-classes" title="永久链接至标题">¶</a></h2>
<dl class="class">
<dt id="turtle.RawTurtle">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">RawTurtle</code><span class="sig-paren">(</span><em class="sig-param">canvas</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.RawTurtle" title="永久链接至目标">¶</a></dt>
<dt id="turtle.RawPen">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">RawPen</code><span class="sig-paren">(</span><em class="sig-param">canvas</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.RawPen" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>canvas</strong> -- 一个 <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> , <a class="reference internal" href="#turtle.ScrolledCanvas" title="turtle.ScrolledCanvas"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScrolledCanvas</span></code></a> 或 <a class="reference internal" href="#turtle.TurtleScreen" title="turtle.TurtleScreen"><code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code></a> 类对象</p>
</dd>
</dl>
<p>创建一个海龟。海龟对象具有 &quot;Turtle/RawTurtle 方法&quot; 一节所述的全部方法。</p>
</dd></dl>

<dl class="class">
<dt id="turtle.Turtle">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">Turtle</code><a class="headerlink" href="#turtle.Turtle" title="永久链接至目标">¶</a></dt>
<dd><p>RawTurtle 的子类，具有相同的接口，但其绘图场所为默认的 <a class="reference internal" href="#turtle.Screen" title="turtle.Screen"><code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code></a> 类对象，在首次使用时自动创建。</p>
</dd></dl>

<dl class="class">
<dt id="turtle.TurtleScreen">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">TurtleScreen</code><span class="sig-paren">(</span><em class="sig-param">cv</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.TurtleScreen" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>cv</strong> -- 一个 <code class="xref py py-class docutils literal notranslate"><span class="pre">tkinter.Canvas</span></code> 类对象</p>
</dd>
</dl>
<p>提供面向屏幕的方法例如 <code class="xref py py-func docutils literal notranslate"><span class="pre">setbg()</span></code> 等。说明见上文。</p>
</dd></dl>

<dl class="class">
<dt id="turtle.Screen">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">Screen</code><a class="headerlink" href="#turtle.Screen" title="永久链接至目标">¶</a></dt>
<dd><p>TurtleScreen 的子类，<a class="reference internal" href="#screenspecific"><span class="std std-ref">增加了四个方法</span></a>.</p>
</dd></dl>

<dl class="class">
<dt id="turtle.ScrolledCanvas">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">ScrolledCanvas</code><span class="sig-paren">(</span><em class="sig-param">master</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.ScrolledCanvas" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>master</strong> -- 可容纳 ScrolledCanvas 的 Tkinter 部件，即添加了滚动条的 Tkinter-canvas</p>
</dd>
</dl>
<p>由 Screen 类使用，使其能够自动提供一个 ScrolledCanvas 作为海龟的绘图场所。</p>
</dd></dl>

<dl class="class">
<dt id="turtle.Shape">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">Shape</code><span class="sig-paren">(</span><em class="sig-param">type_</em>, <em class="sig-param">data</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Shape" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>type_</strong> -- 字符串 &quot;polygon&quot;, &quot;image&quot;, &quot;compound&quot; 其中之一</p>
</dd>
</dl>
<p>实现形状的数据结构。<code class="docutils literal notranslate"><span class="pre">(type_,</span> <span class="pre">data)</span></code> 必须遵循以下定义:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 16%" />
<col style="width: 84%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p><em>type_</em></p></th>
<th class="head"><p><em>data</em></p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>&quot;polygon&quot;</p></td>
<td><p>一个多边形元组，即由坐标值对构成的元组</p></td>
</tr>
<tr class="row-odd"><td><p>&quot;image&quot;</p></td>
<td><p>一个图片  (此形式仅限内部使用!)</p></td>
</tr>
<tr class="row-even"><td><p>&quot;compound&quot;</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">None</span></code> (复合形状必须使用 <a class="reference internal" href="#turtle.Shape.addcomponent" title="turtle.Shape.addcomponent"><code class="xref py py-meth docutils literal notranslate"><span class="pre">addcomponent()</span></code></a> 方法来构建)</p></td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="turtle.Shape.addcomponent">
<code class="sig-name descname">addcomponent</code><span class="sig-paren">(</span><em class="sig-param">poly</em>, <em class="sig-param">fill</em>, <em class="sig-param">outline=None</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Shape.addcomponent" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>poly</strong> -- 一个多边形，即由数值对构成的元组</p></li>
<li><p><strong>fill</strong> -- 一种颜色，将用来填充 <em>poly</em> 指定的多边形</p></li>
<li><p><strong>outline</strong> -- 一种颜色，用于多边形的轮廓 (如有指定)</p></li>
</ul>
</dd>
</dl>
<p>示例:</p>
<div class="highlight-pycon3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">poly</span> <span class="o">=</span> <span class="p">((</span><span class="mi">0</span><span class="p">,</span><span class="mi">0</span><span class="p">),(</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">),(</span><span class="mi">0</span><span class="p">,</span><span class="mi">10</span><span class="p">),(</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span><span class="o">-</span><span class="mi">5</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span> <span class="o">=</span> <span class="n">Shape</span><span class="p">(</span><span class="s2">&quot;compound&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">s</span><span class="o">.</span><span class="n">addcomponent</span><span class="p">(</span><span class="n">poly</span><span class="p">,</span> <span class="s2">&quot;red&quot;</span><span class="p">,</span> <span class="s2">&quot;blue&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># ... add more components and then use register_shape()</span>
</pre></div>
</div>
<p>参见 <a class="reference internal" href="#compoundshapes"><span class="std std-ref">复合形状</span></a>。</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="turtle.Vec2D">
<em class="property">class </em><code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">Vec2D</code><span class="sig-paren">(</span><em class="sig-param">x</em>, <em class="sig-param">y</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.Vec2D" title="永久链接至目标">¶</a></dt>
<dd><p>一个二维矢量类，用来作为实现海龟绘图的辅助类。也可能在海龟绘图程序中使用。派生自元组，因此矢量也属于元组!</p>
<p>提供的运算 (<em>a</em>, <em>b</em> 为矢量, <em>k</em> 为数值):</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">+</span> <span class="pre">b</span></code> 矢量加法</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">-</span> <span class="pre">b</span></code> 矢量减法</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">b</span></code> 内积</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">k</span> <span class="pre">*</span> <span class="pre">a</span></code> 和 <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">*</span> <span class="pre">k</span></code> 与标量相乘</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">abs(a)</span></code> a 的绝对值</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">a.rotate(angle)</span></code> 旋转</p></li>
</ul>
</dd></dl>

</div>
<div class="section" id="help-and-configuration">
<h2>帮助与配置<a class="headerlink" href="#help-and-configuration" title="永久链接至标题">¶</a></h2>
<div class="section" id="how-to-use-help">
<h3>如何使用帮助<a class="headerlink" href="#how-to-use-help" title="永久链接至标题">¶</a></h3>
<p>Screen 和 Turtle 类的公用方法以文档字符串提供了详细的文档。因此可以利用 Python 帮助工具获取这些在线帮助信息:</p>
<ul>
<li><p>当使用 IDLE 时，输入函数/方法调用将弹出工具提示显示其签名和文档字符串的头几行。</p></li>
<li><p>对文法或函数调用 <a class="reference internal" href="functions.html#help" title="help"><code class="xref py py-func docutils literal notranslate"><span class="pre">help()</span></code></a> 将显示其文档字符串:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">Screen</span><span class="o">.</span><span class="n">bgcolor</span><span class="p">)</span>
<span class="go">Help on method bgcolor in module turtle:</span>

<span class="go">bgcolor(self, *args) unbound turtle.Screen method</span>
<span class="go">    Set or return backgroundcolor of the TurtleScreen.</span>

<span class="go">    Arguments (if given): a color string or three numbers</span>
<span class="go">    in the range 0..colormode or a 3-tuple of such numbers.</span>


<span class="go">      &gt;&gt;&gt; screen.bgcolor(&quot;orange&quot;)</span>
<span class="go">      &gt;&gt;&gt; screen.bgcolor()</span>
<span class="go">      &quot;orange&quot;</span>
<span class="go">      &gt;&gt;&gt; screen.bgcolor(0.5,0,0.5)</span>
<span class="go">      &gt;&gt;&gt; screen.bgcolor()</span>
<span class="go">      &quot;#800080&quot;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">Turtle</span><span class="o">.</span><span class="n">penup</span><span class="p">)</span>
<span class="go">Help on method penup in module turtle:</span>

<span class="go">penup(self) unbound turtle.Turtle method</span>
<span class="go">    Pull the pen up -- no drawing when moving.</span>

<span class="go">    Aliases: penup | pu | up</span>

<span class="go">    No argument</span>

<span class="go">    &gt;&gt;&gt; turtle.penup()</span>
</pre></div>
</div>
</li>
<li><p>方法对应函数的文档字符串的形式会有一些修改:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">bgcolor</span><span class="p">)</span>
<span class="go">Help on function bgcolor in module turtle:</span>

<span class="go">bgcolor(*args)</span>
<span class="go">    Set or return backgroundcolor of the TurtleScreen.</span>

<span class="go">    Arguments (if given): a color string or three numbers</span>
<span class="go">    in the range 0..colormode or a 3-tuple of such numbers.</span>

<span class="go">    Example::</span>

<span class="go">      &gt;&gt;&gt; bgcolor(&quot;orange&quot;)</span>
<span class="go">      &gt;&gt;&gt; bgcolor()</span>
<span class="go">      &quot;orange&quot;</span>
<span class="go">      &gt;&gt;&gt; bgcolor(0.5,0,0.5)</span>
<span class="go">      &gt;&gt;&gt; bgcolor()</span>
<span class="go">      &quot;#800080&quot;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">help</span><span class="p">(</span><span class="n">penup</span><span class="p">)</span>
<span class="go">Help on function penup in module turtle:</span>

<span class="go">penup()</span>
<span class="go">    Pull the pen up -- no drawing when moving.</span>

<span class="go">    Aliases: penup | pu | up</span>

<span class="go">    No argument</span>

<span class="go">    Example:</span>
<span class="go">    &gt;&gt;&gt; penup()</span>
</pre></div>
</div>
</li>
</ul>
<p>这些修改版文档字符串是在导入时与方法对应函数的定义一起自动生成的。</p>
</div>
<div class="section" id="translation-of-docstrings-into-different-languages">
<h3>文档字符串翻译为不同的语言<a class="headerlink" href="#translation-of-docstrings-into-different-languages" title="永久链接至标题">¶</a></h3>
<p>可使用工具创建一个字典，键为方法名，值为 Screen 和 Turtle 类公共方法的文档字符串。</p>
<dl class="function">
<dt id="turtle.write_docstringdict">
<code class="sig-prename descclassname">turtle.</code><code class="sig-name descname">write_docstringdict</code><span class="sig-paren">(</span><em class="sig-param">filename=&quot;turtle_docstringdict&quot;</em><span class="sig-paren">)</span><a class="headerlink" href="#turtle.write_docstringdict" title="永久链接至目标">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><p><strong>filename</strong> -- 一个字符串，表示文件名</p>
</dd>
</dl>
<p>创建文档字符串字典并将其写入 filename 指定的 Python 脚本文件。此函数必须显示地调用 (海龟绘图类并不使用此函数)。文档字符串字典将被写入到 Python 脚本文件 <code class="file docutils literal notranslate"><em><span class="pre">filename</span></em><span class="pre">.py</span></code>。该文件可作为模板用来将文档字符串翻译为不同语言。</p>
</dd></dl>

<p>如果你 (或你的学生) 想使用本国语言版本的 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 在线帮助，你必须翻译文档字符串并保存结果文件，例如 <code class="file docutils literal notranslate"><span class="pre">turtle_docstringdict_german.py</span></code>.</p>
<p>如果你在 <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 文件中加入了相应的条目，此字典将在导入模块时被读取并替代原有的英文版文档字符串。</p>
<p>在撰写本文档时已经有了德语和意大利语版的文档字符串字典。(更多需求请联系 <a class="reference external" href="mailto:glingl&#37;&#52;&#48;aon&#46;at">glingl<span>&#64;</span>aon<span>&#46;</span>at</a>)</p>
</div>
<div class="section" id="how-to-configure-screen-and-turtles">
<h3>如何配置 Screen 和 Turtle<a class="headerlink" href="#how-to-configure-screen-and-turtles" title="永久链接至标题">¶</a></h3>
<p>内置的默认配置是模仿旧 turtle 模块的外观和行为，以便尽可能地与其保持兼容。</p>
<p>如果你想使用不同的配置，以便更好地反映此模块的特性或是更适合你的需求，例如在课堂中使用，你可以准备一个配置文件 <code class="docutils literal notranslate"><span class="pre">turtle.cfg</span></code>，该文件将在导入模块时被读取并根据其中的设定修改模块配置。</p>
<p>内置的配置对应以下的 turtle.cfg:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">width</span> <span class="o">=</span> <span class="mf">0.5</span>
<span class="n">height</span> <span class="o">=</span> <span class="mf">0.75</span>
<span class="n">leftright</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">topbottom</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">canvwidth</span> <span class="o">=</span> <span class="mi">400</span>
<span class="n">canvheight</span> <span class="o">=</span> <span class="mi">300</span>
<span class="n">mode</span> <span class="o">=</span> <span class="n">standard</span>
<span class="n">colormode</span> <span class="o">=</span> <span class="mf">1.0</span>
<span class="n">delay</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">undobuffersize</span> <span class="o">=</span> <span class="mi">1000</span>
<span class="n">shape</span> <span class="o">=</span> <span class="n">classic</span>
<span class="n">pencolor</span> <span class="o">=</span> <span class="n">black</span>
<span class="n">fillcolor</span> <span class="o">=</span> <span class="n">black</span>
<span class="n">resizemode</span> <span class="o">=</span> <span class="n">noresize</span>
<span class="n">visible</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">language</span> <span class="o">=</span> <span class="n">english</span>
<span class="n">exampleturtle</span> <span class="o">=</span> <span class="n">turtle</span>
<span class="n">examplescreen</span> <span class="o">=</span> <span class="n">screen</span>
<span class="n">title</span> <span class="o">=</span> <span class="n">Python</span> <span class="n">Turtle</span> <span class="n">Graphics</span>
<span class="n">using_IDLE</span> <span class="o">=</span> <span class="kc">False</span>
</pre></div>
</div>
<p>选定条目的简短说明:</p>
<ul class="simple">
<li><p>开头的四行对应 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.setup()</span></code> 方法的参数。</p></li>
<li><p>第 5 和 6 行对应 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.screensize()</span></code> 方法的参数。</p></li>
<li><p><em>shape</em> 可以是任何内置形状，即: arrow, turtle 等。更多信息可用 <code class="docutils literal notranslate"><span class="pre">help(shape)</span></code> 查看。</p></li>
<li><p>如果你想使用无填充色 (即令海龟变透明)，你必须写 <code class="docutils literal notranslate"><span class="pre">fillcolor</span> <span class="pre">=</span> <span class="pre">&quot;&quot;</span></code> (但 cfg 文件中所有非空字符串都不可加引号)。</p></li>
<li><p>如果你想令海龟反映其状态，你必须使用 <code class="docutils literal notranslate"><span class="pre">resizemode</span> <span class="pre">=</span> <span class="pre">auto</span></code>。</p></li>
<li><p>如果你设置语言例如 <code class="docutils literal notranslate"><span class="pre">language</span> <span class="pre">=</span> <span class="pre">italian</span></code> 则文档字符串字典 <code class="file docutils literal notranslate"><span class="pre">turtle_docstringdict_italian.py</span></code> 将在导入模块时被加载 (如果导入路径即 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 的目录中存在此文件。</p></li>
<li><p><em>exampleturtle</em> 和 <em>examplescreen</em> 条目定义了相应对象在文档字符串中显示的名称。方法文档字符串转换为函数文档字符串时将从文档字符串中删去这些名称。</p></li>
<li><p><em>using_IDLE</em>: 如果你经常使用 IDLE 并启用其 -n 开关 (&quot;无子进程&quot;) 则应将此项设为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，这将阻止 <a class="reference internal" href="#turtle.exitonclick" title="turtle.exitonclick"><code class="xref py py-func docutils literal notranslate"><span class="pre">exitonclick()</span></code></a> 进入主事件循环。</p></li>
</ul>
<p><code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 文件可以保存于 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 所在目录，当前工作目录也可以有一个同名文件。后者会重载覆盖前者的设置。</p>
<p><code class="file docutils literal notranslate"><span class="pre">Lib/turtledemo</span></code> 目录中也有一个 <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 文件。你可以将其作为示例进行研究，并在运行演示时查看其作用效果 (但最好不要在演示查看器中运行)。</p>
</div>
</div>
<div class="section" id="module-turtledemo">
<span id="turtledemo-demo-scripts"></span><h2><a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> --- 演示脚本集<a class="headerlink" href="#module-turtledemo" title="永久链接至标题">¶</a></h2>
<p><a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> 包汇集了一组演示脚本。这些脚本可以通过以下命令打开所提供的演示查看器运行和查看:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">turtledemo</span>
</pre></div>
</div>
<p>此外，你也可以单独运行其中的演示脚本。例如，:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">turtledemo</span><span class="o">.</span><span class="n">bytedesign</span>
</pre></div>
</div>
<p><a class="reference internal" href="#module-turtledemo" title="turtledemo: A viewer for example turtle scripts"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code></a> 包目录中的内容:</p>
<ul class="simple">
<li><p>一个演示查看器 <code class="file docutils literal notranslate"><span class="pre">__main__.py</span></code>，可用来查看脚本的源码并即时运行。</p></li>
<li><p>多个脚本文件，演示 <a class="reference internal" href="#module-turtle" title="turtle: An educational framework for simple graphics applications"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code></a> 模块的不同特性。所有示例可通过 Examples 菜单打开。也可以单独运行每个脚本。</p></li>
<li><p>一个 <code class="file docutils literal notranslate"><span class="pre">turtle.cfg</span></code> 文件，作为说明如何编写并使用模块配置文件的示例模板。</p></li>
</ul>
<p>演示脚本清单如下:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 23%" />
<col style="width: 43%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>名称</p></th>
<th class="head"><p>描述</p></th>
<th class="head"><p>相关特性</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>bytedesign</p></td>
<td><p>复杂的传统海龟绘图模式</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">tracer()</span></code>, delay,
<code class="xref py py-func docutils literal notranslate"><span class="pre">update()</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>chaos</p></td>
<td><p>绘制 Verhulst 动态模型，演示通过计算机的运算可能会生成令人惊叹的结果</p></td>
<td><p>世界坐标系</p></td>
</tr>
<tr class="row-even"><td><p>clock</p></td>
<td><p>绘制模拟时钟显示本机的当前时间</p></td>
<td><p>海龟作为表针, ontimer</p></td>
</tr>
<tr class="row-odd"><td><p>colormixer</p></td>
<td><p>试验 r, g, b 颜色模式</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">ondrag()</span></code> 当鼠标拖动</p></td>
</tr>
<tr class="row-even"><td><p>forest</p></td>
<td><p>绘制 3 棵广度优先树</p></td>
<td><p>随机化</p></td>
</tr>
<tr class="row-odd"><td><p>fractalcurves</p></td>
<td><p>绘制 Hilbert &amp; Koch 曲线</p></td>
<td><p>递归</p></td>
</tr>
<tr class="row-even"><td><p>lindenmayer</p></td>
<td><p>文化数学 (印度装饰艺术)</p></td>
<td><p>L-系统</p></td>
</tr>
<tr class="row-odd"><td><p>minimal_hanoi</p></td>
<td><p>汉诺塔</p></td>
<td><p>矩形海龟作为汉诺盘 (shape, shapesize)</p></td>
</tr>
<tr class="row-even"><td><p>nim</p></td>
<td><p>玩经典的“尼姆”游戏，开始时有三堆小棒，与电脑对战。</p></td>
<td><p>海龟作为小棒，事件驱动 (鼠标, 键盘)</p></td>
</tr>
<tr class="row-odd"><td><p>paint</p></td>
<td><p>超极简主义绘画程序</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">onclick()</span></code> 当鼠标点击</p></td>
</tr>
<tr class="row-even"><td><p>peace</p></td>
<td><p>初级技巧</p></td>
<td><p>海龟: 外观与动画</p></td>
</tr>
<tr class="row-odd"><td><p>penrose</p></td>
<td><p>非周期性地使用风筝和飞镖形状铺满平面</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">stamp()</span></code> 印章</p></td>
</tr>
<tr class="row-even"><td><p>planet_and_moon</p></td>
<td><p>模拟引力系统</p></td>
<td><p>复合开关, <code class="xref py py-class docutils literal notranslate"><span class="pre">Vec2D</span></code> 类</p></td>
</tr>
<tr class="row-odd"><td><p>round_dance</p></td>
<td><p>两两相对并不断旋转舞蹈的海龟</p></td>
<td><p>复合形状, clone shapesize, tilt, get_shapepoly, update</p></td>
</tr>
<tr class="row-even"><td><p>sorting_animate</p></td>
<td><p>动态演示不同的排序方法</p></td>
<td><p>简单对齐, 随机化</p></td>
</tr>
<tr class="row-odd"><td><p>tree</p></td>
<td><p>一棵 (图形化的) 广度优先树 (使用生成器)</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code> 克隆</p></td>
</tr>
<tr class="row-even"><td><p>two_canvases</p></td>
<td><p>简单设计</p></td>
<td><p>两块画布上的海龟</p></td>
</tr>
<tr class="row-odd"><td><p>wikipedia</p></td>
<td><p>一个来自介绍海龟绘图的维基百科文章的图案</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">clone()</span></code>,
<code class="xref py py-func docutils literal notranslate"><span class="pre">undo()</span></code></p></td>
</tr>
<tr class="row-even"><td><p>yinyang</p></td>
<td><p>另一个初级示例</p></td>
<td><p><code class="xref py py-func docutils literal notranslate"><span class="pre">circle()</span></code> 画圆</p></td>
</tr>
</tbody>
</table>
<p>祝你玩得开心！</p>
</div>
<div class="section" id="changes-since-python-2-6">
<h2>Python 2.6 之后的变化<a class="headerlink" href="#changes-since-python-2-6" title="永久链接至标题">¶</a></h2>
<ul class="simple">
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.tracer()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.window_width()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.window_height()</span></code> 方法已被去除。具有这些名称和功能的方法现在只限于 <code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code> 类的方法。但其对应的函数仍然可用。(实际上在 Python 2.6 中这些方法就已经只是从对应的 <code class="xref py py-class docutils literal notranslate"><span class="pre">TurtleScreen</span></code>/<code class="xref py py-class docutils literal notranslate"><span class="pre">Screen</span></code> 类的方法复制而来。)</p></li>
<li><p><code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.fill()</span></code> 方法已被去除。<code class="xref py py-meth docutils literal notranslate"><span class="pre">begin_fill()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">end_fill()</span></code> 的行为则有细微改变: 现在每个填充过程必须以一个 <code class="docutils literal notranslate"><span class="pre">end_fill()</span></code> 调用来结束。</p></li>
<li><p>新增了一个 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.filling()</span></code> 方法。该方法返回一个布尔值: 如果填充过程正在进行为 <code class="docutils literal notranslate"><span class="pre">True</span></code>，否则为 <code class="docutils literal notranslate"><span class="pre">False</span></code>。此行为相当于 Python 2.6 中不带参数的 <code class="docutils literal notranslate"><span class="pre">fill()</span></code> 调用。</p></li>
</ul>
</div>
<div class="section" id="changes-since-python-3-0">
<h2>Python 3.0 之后的变化<a class="headerlink" href="#changes-since-python-3-0" title="永久链接至标题">¶</a></h2>
<ul class="simple">
<li><p>新增了 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.shearfactor()</span></code>, <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.shapetransform()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.get_shapepoly()</span></code> 方法。这样就可以使用所有标准线性变换来调整海龟形状。<code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.tiltangle()</span></code> 的功能已被加强: 现在可被用来获取或设置倾角。<code class="xref py py-meth docutils literal notranslate"><span class="pre">Turtle.settiltangle()</span></code> 已弃用。</p></li>
<li><p>新增了 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkeypress()</span></code> 方法作为对 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkey()</span></code> 的补充，实际就是将行为绑定到 keyrelease 事件。后者相应增加了一个别名: <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.onkeyrelease()</span></code>。</p></li>
<li><p>新增了  <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.mainloop()</span></code> 方法。这样当仅需使用 Screen 和 Turtle 对象时不需要再额外导入 <code class="xref py py-func docutils literal notranslate"><span class="pre">mainloop()</span></code>。</p></li>
<li><p>新增了两个方法 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.textinput()</span></code> 和 <code class="xref py py-meth docutils literal notranslate"><span class="pre">Screen.numinput()</span></code>。用来弹出对话框接受输入并分别返回字符串和数值。</p></li>
<li><p>两个新的示例脚本 <code class="file docutils literal notranslate"><span class="pre">tdemo_nim.py</span></code> 和 <code class="file docutils literal notranslate"><span class="pre">tdemo_round_dance.py</span></code> 被加入到 <code class="file docutils literal notranslate"><span class="pre">Lib/turtledemo</span></code> 目录中。</p></li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">目录</a></h3>
  <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtle</span></code> --- 海龟绘图</a><ul>
<li><a class="reference internal" href="#introduction">概述</a></li>
<li><a class="reference internal" href="#overview-of-available-turtle-and-screen-methods">可用的 Turtle 和 Screen 方法概览</a><ul>
<li><a class="reference internal" href="#turtle-methods">Turtle 方法</a></li>
<li><a class="reference internal" href="#methods-of-turtlescreen-screen">TurtleScreen/Screen 方法</a></li>
</ul>
</li>
<li><a class="reference internal" href="#methods-of-rawturtle-turtle-and-corresponding-functions">RawTurtle/Turtle 方法和对应函数</a><ul>
<li><a class="reference internal" href="#turtle-motion">海龟动作</a></li>
<li><a class="reference internal" href="#tell-turtle-s-state">获取海龟的状态</a></li>
<li><a class="reference internal" href="#settings-for-measurement">度量单位设置</a></li>
<li><a class="reference internal" href="#pen-control">画笔控制</a><ul>
<li><a class="reference internal" href="#drawing-state">绘图状态</a></li>
<li><a class="reference internal" href="#color-control">颜色控制</a></li>
<li><a class="reference internal" href="#filling">填充</a></li>
<li><a class="reference internal" href="#more-drawing-control">更多绘图控制</a></li>
</ul>
</li>
<li><a class="reference internal" href="#turtle-state">海龟状态</a><ul>
<li><a class="reference internal" href="#visibility">可见性</a></li>
<li><a class="reference internal" href="#appearance">外观</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-events">使用事件</a></li>
<li><a class="reference internal" href="#special-turtle-methods">特殊海龟方法</a></li>
<li><a class="reference internal" href="#compound-shapes">复合形状</a></li>
</ul>
</li>
<li><a class="reference internal" href="#methods-of-turtlescreen-screen-and-corresponding-functions">TurtleScreen/Screen 方法及对应函数</a><ul>
<li><a class="reference internal" href="#window-control">窗口控制</a></li>
<li><a class="reference internal" href="#animation-control">动画控制</a></li>
<li><a class="reference internal" href="#using-screen-events">使用屏幕事件</a></li>
<li><a class="reference internal" href="#input-methods">输入方法</a></li>
<li><a class="reference internal" href="#settings-and-special-methods">设置与特殊方法</a></li>
<li><a class="reference internal" href="#methods-specific-to-screen-not-inherited-from-turtlescreen">Screen 专有方法, 而非继承自 TurtleScreen</a></li>
</ul>
</li>
<li><a class="reference internal" href="#public-classes">公共类</a></li>
<li><a class="reference internal" href="#help-and-configuration">帮助与配置</a><ul>
<li><a class="reference internal" href="#how-to-use-help">如何使用帮助</a></li>
<li><a class="reference internal" href="#translation-of-docstrings-into-different-languages">文档字符串翻译为不同的语言</a></li>
<li><a class="reference internal" href="#how-to-configure-screen-and-turtles">如何配置 Screen 和 Turtle</a></li>
</ul>
</li>
<li><a class="reference internal" href="#module-turtledemo"><code class="xref py py-mod docutils literal notranslate"><span class="pre">turtledemo</span></code> --- 演示脚本集</a></li>
<li><a class="reference internal" href="#changes-since-python-2-6">Python 2.6 之后的变化</a></li>
<li><a class="reference internal" href="#changes-since-python-3-0">Python 3.0 之后的变化</a></li>
</ul>
</li>
</ul>

  <h4>上一个主题</h4>
  <p class="topless"><a href="frameworks.html"
                        title="上一章">程序框架</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="cmd.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cmd</span></code> --- 支持面向行的命令解释器</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/turtle.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="cmd.html" title="cmd --- 支持面向行的命令解释器"
             >下一页</a> |</li>
        <li class="right" >
          <a href="frameworks.html" title="程序框架"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="frameworks.html" >程序框架</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>